我有一个有 3 个孩子的相对布局。
- 第一个是 ImageView 封面。
- 第二个是父级的 ImageView 头像中心和
- 第三是头像下方的 TextView 应用名称和水平居中。
理论上它应该可以工作,但我的布局没有在头像下方放置文本。相对布局有什么问题?
P/S: android:layout_below="@+id/logo2" 和 android:layout_below="@id/logo2" 我都试过了,但还是不行!
谢谢!
这是我的 xml 布局。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content">
<ImageView android:layout_width="match_parent" android:layout_height="wrap_content" android:adjustViewBounds="true" android:src="@drawable/android_apple"/>
<ImageView android:id="@+id/logo2" android:layout_width="64dp" android:layout_height="64dp" android:layout_centerInParent="true" android:src="@drawable/default_avatar"/>
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/logo2" android:layout_centerHorizontal="true" android:text="AAAAAAA" android:textStyle="bold"/> </RelativeLayout> |
结果:

更改父级相对布局高度以匹配父级。它会起作用的。
喜欢这个
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent">
<ImageView android:layout_width="match_parent" android:layout_height="wrap_content" android:adjustViewBounds="true" android:src="@drawable/android_apple" android:layout_alignParentTop="true" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" />
<ImageView android:id="@+id/logo2" android:layout_width="64dp" android:layout_height="64dp" android:layout_centerInParent="true" android:src="@drawable/default_avatar"/>
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/logo2" android:layout_centerHorizontal="true" android:text="AAAAAAA" android:textStyle="bold"/> </RelativeLayout> |
本文来自网络,不代表无忧安卓网立场,转载请注明出处。