【发布时间】:2016-04-25 07:04:00
【问题描述】:
我遇到了一个奇怪的问题,下面是我的布局:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<ImageView
android:src="@color/colorAccent"
android:layout_width="match_parent"
android:layout_height="200dp"/>
<ImageView
android:id="@+id/image"
android:src="@mipmap/ic_launcher"
android:layout_centerInParent="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:text="text"
android:layout_below="@+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</RelativeLayout>
TextView 没有低于预期的ImageView,它低于ImageView 的原始位置。
如果我将RelativeLayout 的layout_height 设置为200dp 或match_parent,它工作正常。
我该如何解决?
【问题讨论】:
-
嗯,这是一个相对的布局。您需要指定每个元素相对于另一个元素的位置。要对齐行或列中的所有元素,请使用 LinearLayout
-
为什么要添加第一个图像视图?如果要更改布局的背景颜色,还有另一种方法。
-
使用 match_parent 而不是 wrap_content 到根布局。
-
不要对“PINK”颜色使用单独的图像视图,您可以使用 setBackground 属性将颜色设置为相对布局。你也使用 android:layout_centerInParent="true" 作为第二个 imageview .. 所以如果你想在 ImageView 下设置 TextView,请不要使用该属性。希望它会有所帮助:)
标签: android android-layout user-interface android-relativelayout