我想要一个视图来匹配其父级的高度,如下所示:
<RelativeLayout
layout_height="wrap_content">
<LinearLayout
id="@+id/A"
layout_height="wrap_content"
layout_alignParentTop="true">
...
</LinearLayout>
<LinearLayout
id="@+id/B"
layout_height="match_parent" <-- possible?
layout_alignParentTop="true">
...
</LinearLayout>
</RelativeLayout>
所以线性布局A膨胀为100dp。线性布局B膨胀到约50 dp高。但是我想让它与父母的高度相匹配,在这种情况下应该是100dp来容纳A.有没有办法做到这一点?我的布局如上所述,但B没有扩展到A为父容器设置的全高。
由于
答案 0 :(得分:6)
所以,match_parent取代了fill_parent。我发现这个问题由罗曼·盖伊回答。
combining wrap_content on parent and fill_parent on child
他说这应该不起作用,但他们让它适用于LinearLayout,并且他最近使它适用于Honeycomb的FrameLayout。
基于此,我推测这可能不适用于RelativeLayout?
尝试使用LinearLayout或FrameLayout而不是RelativeLayout,看看是否有效?
编辑以下是我的所作所为:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<FrameLayout
android:layout_height="wrap_content"
android:layout_width="match_parent">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<Button
android:layout_height="match_parent"
android:layout_width="match_parent"
android:text="TEST"/>
</LinearLayout>
</FrameLayout>
</LinearLayout>
字符串的值:
<string name="hello">Hello World, Game! Hello World, Game! Hello World, Game! Hello World, Game! Hello World, Game! Hello World, Game! Hello World, Game! Hello World, Game! Hello World, Game! Hello World, Game! Hello World, Game! Hello World, Game! Hello World, Game! Hello World, Game! Hello World, Game! Hello World, Game! Hello World, Game! Hello World, Game! Hello World, Game! Hello World, Game! Hello World, Game! Hello World, Game! Hello World, Game! Hello World, Game! Hello World, Game! Hello World, Game! Hello World, Game! Hello World, Game! Hello World, Game! Hello World, Game!</string>
答案 1 :(得分:-1)
为什么不设置alignParentTop&amp; alignParentBottom是真的吗?它应该适合你。