RelativeLayout正在全屏换行

为什么FOOBARZ在layout_height="fill_parent"时候底部没有layout_height="fill_parent" ?换句话说,所有元素都是wrap_content的高度? 在这里输入图像描述

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">
    <TextView
        android:id="@+id/feed_u"
        android:layout_width="50dip"
        android:layout_height="50dip"
        android:layout_marginLeft="5dip"
        android:scaleType="centerCrop"
        android:drawableTop="@android:drawable/presence_online"
        android:text="U" />
    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@id/feed_u">
        <ImageView
            android:id="@+id/feed_h"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="true"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@android:drawable/btn_minus" />
        <ImageView
            android:id="@+id/feed_ha"
            android:layout_toLeftOf="@id/feed_h"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="true"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@android:drawable/btn_plus" />
        <TextView
            android:id="@+id/feed_t"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Title">
        </TextView>
        <TextView
            android:id="@+id/feed_a"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Band"
            android:layout_below="@id/feed_t">
        </TextView>
        <TextView
            android:id="@+id/feed_s"
            android:layout_below="@id/feed_a"
            android:text="S"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content">
        </TextView>
        <TextView
            android:id="@+id/feed_tm"
            android:layout_alignParentBottom="true"
            android:layout_alignParentRight="true"
            android:text="FOOBARZ"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content">
        </TextView>

    </RelativeLayout>
</RelativeLayout>

RelativeLayout文档:

课程概述

一个布局,其中的孩子的位置可以描述为相互之间或父母。

请注意,您不能在RelativeLayout的大小和子级的位置之间存在循环依赖关系。 例如,您不能有一个RelativeLayout,其高度设置为WRAP_CONTENT,并且子设置为ALIGN_PARENT_BOTTOM

类文档

这正是你的情况。 RelativeLayout不能做到这一点。


对于那些正在寻找解决方案的人,像我一样,可以使用FrameLayout而不是RelativeLayout

然后,您可以将重力设置为右下角,如下所示

<TextView
    android:layout_gravity="bottom|right"
    android:text="FOOBARZ"
    android:layout_height="wrap_content"
    android:layout_width="wrap_content">
</TextView>

您已将RelativeLayout设置为"wrap_content" ,将TextView设置为android:layout_alignParentBottom="true" ,因此它会自动尝试将RelativeLayout拉伸到底部。 不要在Relative Layout中使用这种依赖关系,因为它可以算作“循环依赖”。

来自RelativeLayout的文档:

请注意,您不能在RelativeLayout的大小和子级的位置之间存在循环依赖关系。 例如,您不能有一个RelativeLayout,其高度设置为WRAP_CONTENT并且子设置为ALIGN_PARENT_BOTTOM

尝试将TextView与父亲RelativeLayout以外的东西对齐,但要小心这个问题:
循环依赖关系,需要一些精确的代码帮助

或者,尝试添加更复杂的内部布局。

链接地址: http://www.djcxy.com/p/84743.html

上一篇: RelativeLayout is taking fullscreen for wrap

下一篇: Dynamically Add Views into View