【发布时间】:2014-07-18 23:54:15
【问题描述】:
当我在ImageView 中加载图像(更具体地说,是纵向形状的图像)时,该图像有时会覆盖Button 上方的ImageView。 ImageView 将 layout_width 和 layout_height 设置为 wrap_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>
【问题讨论】:
-
您可以在
Button中使用android:layout_above="@+id/imageView1" -
有什么办法可以说上面有多少像素?
-
你不应该使用像素,而是使用
dp。 -
@Apoorv 我使用 dp。你没有回答我的问题。
-
使用
android:layout_marginBottom=""给Button以下的边距
标签: android xml button layout imageview