关于 android:layout_below 在 RelativeLayout 中不起作用

我有一个有 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>

 

本文来自网络,不代表无忧安卓网立场,转载请注明出处。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值