Android ImageView中加载的图像正在隐藏按钮
当我在Android ImageView中加载的图像正在隐藏按钮,android,xml,button,layout,imageview,Android,Xml,Button,Layout,Imageview,当我在ImageView中加载图像(更具体地说,是肖像形状的图像)时,该图像有时会覆盖ImageView上方的按钮。ImageView将layout\u width和layout\u height设置为wrap\u content。我的要求是,ImageView将包装内容,但不会覆盖按钮。我不想硬编码像素值 布局: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:too
ImageView
中加载图像(更具体地说,是肖像形状的图像)时,该图像有时会覆盖ImageView
上方的按钮。ImageView
将layout\u width
和layout\u height
设置为wrap\u content
。我的要求是,ImageView
将包装内容,但不会覆盖按钮。我不想硬编码像素值
布局:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="mg.colorfilters.ResultActivity$PlaceholderFragment" >
<Button
android:id="@+id/button1"
android:layout_width="320dp"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:background="@color/red"
android:text="@string/string3"
android:textStyle="bold"
android:textColor="@color/white"
android:onClick="loadImageWithFilterOrSaveImage" />
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:src="@drawable/abc_ab_bottom_solid_dark_holo"
android:contentDescription="@string/string4" />
</RelativeLayout>
在Layout.xml中
请在上面插入android:layout\u=“@+id/button1
标记中的行。您可以在相对布局中使用滚动视图,在滚动视图中使用垂直方向的线性布局……然后在线性布局中添加按钮和图像视图……我没有尝试过,但我认为这会起作用:D您希望图像位于中心吗
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
如果是,则可能希望将按钮代码放在ImageView代码下面,如
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:src="@drawable/abc_ab_bottom_solid_dark_holo"
android:contentDescription="@string/string4" />
<Button
android:id="@+id/button1"
android:layout_width="320dp"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:background="@color/red"
android:text="@string/string3"
android:textStyle="bold"
android:textColor="@color/white"
android:onClick="loadImageWithFilterOrSaveImage" />
这样按钮将始终位于顶部。若图像较大,按钮将显示在其顶部。只有在您同意此行为的情况下才使用此解决方案。您可以在按钮中使用android:layout_over=“@+id/imageView1”
是否有任何方法提及上面有多少像素?您不应该使用像素而使用dp
。@Apoorv我使用dp。您没有回答我的问题。请使用android:layout\u marginBottom=“
在按钮下方留出空白
是的,我希望图像位于中间。您的解决方案非常接近我想要的解决方案,但不是确切的解决方案。您希望图像位于屏幕的中心,并且希望按钮位于中心水平和顶部对齐。当图像尺寸增大时会发生什么?有些东西必须让路,或者您必须将“最大尺寸”设置为“图像视图”。我们可以调整图像视图的大小,以保持加载图像的纵横比。是的,我们可以。我认为设置最大尺寸应该考虑纵横比。(如果你这样做了,记得做dp-px计算,因为你需要dp中的尺寸,但它是在px中设置的)我已经找到了。使用android:maxHeight=“300dp”和android:adjustViewBounds=“true”。在RelativeLayout中提及相对维度的任何方式。如果我使用布局重量,我会收到警告。