【问题标题】:android:layout_width="wrap_content" does not work in a RelativeLayoutandroid:layout_width="wrap_content" 在 RelativeLayout 中不起作用
【发布时间】:2014-06-01 12:43:29
【问题描述】:

答案herehere 断言android:layout_alignParent* 属性会在RelativeLayout 和子视图之间创建循环引用。然而,给定一个简单的布局没有任何android:layout_alignParent*属性:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@android:color/white"
    >
    <TextView
        android:text="test text blah blah"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@android:color/holo_orange_dark"
        android:textColor="@android:color/black"
        />
</RelativeLayout>

RelativeLayout 的布局宽度原来是 match_parent,而不是上面 XML 中指定的 wrap_content

发生了什么事?

【问题讨论】:

    标签: android android-layout


    【解决方案1】:

    显然,ListView 项的layout_width 自动更改为match_parent。上面的布局在 ListView 之外工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-10-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-30
      相关资源
      最近更新 更多