如何制作的LinearLayout在RelativeLayout的填充剩余空间? [英] How to make a linearlayout filling remaining space in a relativelayout?
问题描述
我有一个RelativeLayout的三个linearlayouts儿童。最后一个有一个固定的高度,并具有机器人:layout_alignParentBottom设置为真。而中间的一个适当定位低于第一个,它进入至于屏幕的底部,使得其下部由第三个重叠
怎么了?
感谢
< XML版本=1.0编码=UTF-8&GT?;
< RelativeLayout的
的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT>
<的LinearLayout
机器人:ID =@ + ID /类别
机器人:layout_width =FILL_PARENT
机器人:layout_height =50dp
机器人:layout_alignParentTop =真
机器人:方向=横向>
< ImageView的
机器人:ID =@ + ID / back_btn
机器人:layout_width =29dp
机器人:layout_height =34dp
机器人:layout_gravity =center_vertical
机器人:SRC =@可绘制/ red_arrow_left/>
<的TextView
机器人:ID =@ + ID / cat_name
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_gravity =center_vertical
机器人:重力=中心
机器人:TEXTSIZE =20SP/>
< / LinearLayout中>
<的LinearLayout
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:layout_below =@ + ID /类别
机器人:layout_marginTop =10dp
机器人:方向=横向>
<的ListView
机器人:ID =@ + ID / Android的:清单
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:背景=@机器人:彩色/白
机器人:cacheColorHint =@机器人:彩色/白/>
<的TextView
机器人:ID =@ + ID /安卓:空
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:背景=@机器人:彩色/白
机器人:cacheColorHint =@机器人:彩色/白
机器人:填充=10dp
机器人:文本=@字符串/ no_item/>
< / LinearLayout中>
<的LinearLayout
的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:ID =@ + ID / nav_bar
机器人:layout_width =FILL_PARENT
机器人:layout_height =40dp
机器人:layout_alignParentBottom =真
机器人:方向=横向>
//东东
< / LinearLayout中>
< / RelativeLayout的>
拿去......的解决方案是非常简单的!你忘了说你想说的第二线的布局应该是上面第三个:)是的,第二线的布局必须具有安卓layout_below =@ + ID /类别
和安卓layout_above =@ + ID / nav_bar
。我测试了它和它的作品。
不过,当然,你可以用重量来归档相同的结果,它只是将是更难...
您的XML与我提到的变化(在Eclipse测试它):
< XML版本=1.0编码=UTF-8&GT?;
< RelativeLayout的
的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT>
<的LinearLayout
机器人:ID =@ + ID /类别
机器人:layout_width =FILL_PARENT
机器人:layout_height =50dp
机器人:layout_alignParentTop =真
机器人:方向=横向>
< ImageView的
机器人:ID =@ + ID / back_btn
机器人:layout_width =29dp
机器人:layout_height =34dp
机器人:layout_gravity =center_vertical
机器人:SRC =@可绘制/ red_arrow_left/>
<的TextView
机器人:ID =@ + ID / cat_name
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_gravity =center_vertical
机器人:重力=中心
机器人:TEXTSIZE =20SP/>
< / LinearLayout中>
<的LinearLayout
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:layout_above =@ + ID / nav_bar
机器人:layout_below =@ + ID /类别
机器人:layout_marginTop =10dp
机器人:方向=横向>
<的ListView
机器人:ID =@ + ID / Android的:清单
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:背景=@机器人:彩色/白
机器人:cacheColorHint =@机器人:彩色/白/>
<的TextView
机器人:ID =@ + ID /安卓:空
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:背景=@机器人:彩色/白
机器人:cacheColorHint =@机器人:彩色/白
机器人:填充=10dp
机器人:文本=@字符串/ no_item/>
< / LinearLayout中>
<的LinearLayout
的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:ID =@ + ID / nav_bar
机器人:layout_width =FILL_PARENT
机器人:layout_height =40dp
机器人:layout_alignParentBottom =真
机器人:方向=横向>
//东东
< / LinearLayout中>
< / RelativeLayout的>
I've got a relativelayout with three linearlayouts as children. The last one has a fixed height and has android:layout_alignParentBottom set to "true". While the middle one is properly positioned below the first one, it goes as far as the bottom of the screen, so that its lower part is overlapped by the third one.
What's wrong?
Thanks
<?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="fill_parent" >
<LinearLayout
android:id="@+id/category"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_alignParentTop="true"
android:orientation="horizontal" >
<ImageView
android:id="@+id/back_btn"
android:layout_width="29dp"
android:layout_height="34dp"
android:layout_gravity="center_vertical"
android:src="@drawable/red_arrow_left" />
<TextView
android:id="@+id/cat_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="center"
android:textSize="20sp" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@+id/category"
android:layout_marginTop="10dp"
android:orientation="horizontal" >
<ListView
android:id="@+id/android:list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/white"
android:cacheColorHint="@android:color/white" />
<TextView
android:id="@+id/android:empty"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/white"
android:cacheColorHint="@android:color/white"
android:padding="10dp"
android:text="@string/no_item" />
</LinearLayout>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/nav_bar"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:layout_alignParentBottom="true"
android:orientation="horizontal" >
//stuff
</LinearLayout>
</RelativeLayout>
Nooo... the solution is much simpler! You forgot to say you want to say the second linear layout should be above the third one :) Yes, the second linear layout must have BOTH android:layout_below="@+id/category"
and android:layout_above="@+id/nav_bar"
. I tested it and it works.
But of course, you can use weights to archive the same results, it's just going to be harder...
Your XML with the change I mentioned (tested it in eclipse):
<?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="fill_parent" >
<LinearLayout
android:id="@+id/category"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_alignParentTop="true"
android:orientation="horizontal" >
<ImageView
android:id="@+id/back_btn"
android:layout_width="29dp"
android:layout_height="34dp"
android:layout_gravity="center_vertical"
android:src="@drawable/red_arrow_left" />
<TextView
android:id="@+id/cat_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="center"
android:textSize="20sp" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="@+id/nav_bar"
android:layout_below="@+id/category"
android:layout_marginTop="10dp"
android:orientation="horizontal" >
<ListView
android:id="@+id/android:list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/white"
android:cacheColorHint="@android:color/white" />
<TextView
android:id="@+id/android:empty"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/white"
android:cacheColorHint="@android:color/white"
android:padding="10dp"
android:text="@string/no_item" />
</LinearLayout>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/nav_bar"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:layout_alignParentBottom="true"
android:orientation="horizontal" >
//stuff
</LinearLayout>
</RelativeLayout>
这篇关于如何制作的LinearLayout在RelativeLayout的填充剩余空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!