考虑以下RelativeLayout作为列表视图项:
```xml ```
```xml ```
<?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/bigfoo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:text="bigfoo"
android:textSize="60sp"/>
<TextView
android:id="@+id/foo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/bigfoo"
android:layout_centerVertical="true"
android:text="foo"/>
<TextView
android:id="@+id/bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@id/foo"
android:layout_alignLeft="@id/foo"
android:text="bar"/>
</RelativeLayout>
在使用 Android JB/API 17 设备上的 hierarchyviewer
进行调查后,bar
的高度为 0。
编辑:期望结果:
问题:这种相对布局行为的解释是什么,如何修复布局以满足要求:使 foo
在 bigfoo
的中间(垂直方向)且 bar
在 foo
上方?
android:layout_below="@id/foo"
而不是android:layout_above="@id/foo"
。但问题仍然是为什么会发生+1。 - Shakeeb Ayazandroid:layout_below="@id/foo"
,它实际上可以工作吗? - pkk