RelativeLayout的高度,以填补剩余空间 [英] RelativeLayout height to fill remaining space
本文介绍了RelativeLayout的高度,以填补剩余空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下的布局,我的xml文件:
< RelativeLayout的机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT> <的FrameLayout机器人:ID =@ + ID / logoLayout
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT>
- 一些图片
< /&的FrameLayout GT;
< RelativeLayout的机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:比重=中心
机器人:方向=垂直
机器人:layout_below =@ + ID / logoLayout> 按钮1
按钮2
按钮3
按钮4 < / RelativeLayout的> < RelativeLayout的机器人:方向=横向
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_margin =5dip
机器人:layout_alignParentBottom =真正的> 按钮5
< / RelativeLayout的><&RelativeLayout的GT;
也许我没有做到这一点的最佳途径。我想:有一个包含4个按钮使用的顶部和底部之间布局的整个空间布局,我想有同样安排在布局的按钮
。事情是这样的: http://img16.imageshack.us/i/androidq.png /
我添加了整个布局code:
<?XML版本=1.0编码=UTF-8&GT?;
<的RelativeLayout的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:背景=@绘制/背景>
<! - 页面的标题 - >
<的FrameLayout机器人:ID =@ + ID / logoLayout
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT> < ImageView的机器人:ID =@ + ID / logoBackground
机器人:SRC =@绘制/ logo_background_small
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT/> < ImageView的机器人:ID =@ + ID / logoImage
机器人:SRC =@绘制/ logo_small
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_gravity =左
机器人:比重=中心
机器人:填充=3dip/> <的TextView的android:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:文字=@字符串/曲目
机器人:layout_gravity =中心
机器人:重力=右
机器人:TEXTSIZE =22dip
机器人:文字颜色=#FFFFFF
机器人:填充=3dip>
< / TextView的> < /&的FrameLayout GT;
<的RelativeLayout的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:比重=中心
机器人:方向=垂直
机器人:layout_below =@ + ID / logoLayout> <按钮机器人:ID =@ + ID / BTN1
机器人:layout_height =WRAP_CONTENT
机器人:layout_width =250dip
机器人:drawableLeft =@绘制/ img_small_btn_look_around
机器人:背景=@绘制/ main_long_menu_button
机器人:文字=@字符串/ BTN1
机器人:TEXTSIZE =18dip
机器人:文字颜色=#FFFFFF
机器人:layout_marginTop =20dip
安卓的onClick =btnMyTracksOnClick>
< /按钮> <按钮机器人:ID =@ + ID / BTN2
机器人:layout_height =WRAP_CONTENT
机器人:layout_width =250dip
机器人:drawableLeft =@绘制/ img_small_btn_look_around
机器人:背景=@绘制/ main_long_menu_button
机器人:文字=@字符串/ BTN2
机器人:TEXTSIZE =18dip
机器人:文字颜色=#FFFFFF
机器人:layout_marginTop =20dip
机器人:layout_below =@ + ID / BTN1>
< /按钮> <按钮机器人:ID =@ + ID / btn3
机器人:layout_height =WRAP_CONTENT
机器人:layout_width =250dip
机器人:drawableLeft =@绘制/ img_small_btn_look_around
机器人:背景=@绘制/ main_long_menu_button
机器人:文字=@字符串/ btn3
机器人:TEXTSIZE =18dip
机器人:文字颜色=#FFFFFF
机器人:layout_marginTop =20dip
机器人:layout_below =@ + ID / BTN2>
< /按钮> <按钮机器人:ID =@ + ID / btn4
机器人:layout_height =WRAP_CONTENT
机器人:layout_width =250dip
机器人:drawableLeft =@绘制/ img_small_btn_look_around
机器人:背景=@绘制/ main_long_menu_button
机器人:文字=@字符串/ btn4
机器人:TEXTSIZE =18dip
机器人:文字颜色=#FFFFFF
机器人:layout_marginTop =20dip
机器人:layout_below =@ + ID / BT3>
< /按钮>
< / RelativeLayout的> <的RelativeLayout的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:方向=横向
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_margin =5dip
机器人:layout_alignParentBottom =真正的> <按钮的android:layout_width =90dip
机器人:layout_height =WRAP_CONTENT
机器人:TEXTSIZE =20dip
机器人:文字颜色=#FFFFFF
机器人:layout_alignParentLeft =真
机器人:背景=@绘制/ sett_menu_button
机器人:文字=@字符串/后退
机器人:layout_marginLeft =3dip/> < / RelativeLayout的> < / RelativeLayout的>
解决方案
尝试更改
< RelativeLayout的机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:比重=中心
机器人:方向=垂直
机器人:layout_below =@ + ID / logoLayout> 按钮1
按钮2
按钮3
按钮4< / RelativeLayout的>
到
<的LinearLayout的android:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:比重=中心
机器人:方向=垂直
机器人:layout_below =@ + ID / logoLayout> <! - 例如按钮 - >
<按钮的android:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT机器人:layout_weight =1>< /按钮>
< / LinearLayout中>
在layout_weight应均匀空间,它
希望工程
I have the following layout in my xml file:
<RelativeLayout android:layout_width="fill_parent"
android:layout_height="fill_parent">
<FrameLayout android:id="@+id/logoLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
-- some images
</FrameLayout>
<RelativeLayout android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical"
android:layout_below="@+id/logoLayout">
Button 1
Button 2
Button 3
Button 4
</RelativeLayout>
<RelativeLayout android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="5dip"
android:layout_alignParentBottom="true">
Button 5
</RelativeLayout>
<RelativeLayout>
Maybe I didn't do it in the best way. What I want: have the Layout that contains the 4 buttons to use the entire space between the top and bottom layout, and I want to have the button equally arranged in the layout.
Something like this:http://img16.imageshack.us/i/androidq.png/
I add the whole layout code:
<?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"
android:background="@drawable/background">
<!--The header of the page-->
<FrameLayout android:id="@+id/logoLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ImageView android:id="@+id/logoBackground"
android:src="@drawable/logo_background_small"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<ImageView android:id="@+id/logoImage"
android:src="@drawable/logo_small"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:gravity="center"
android:padding="3dip"/>
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/tracks"
android:layout_gravity="center"
android:gravity="right"
android:textSize="22dip"
android:textColor="#ffffff"
android:padding="3dip">
</TextView>
</FrameLayout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical"
android:layout_below="@+id/logoLayout">
<Button android:id="@+id/btn1"
android:layout_height="wrap_content"
android:layout_width="250dip"
android:drawableLeft="@drawable/img_small_btn_look_around"
android:background="@drawable/main_long_menu_button"
android:text="@string/btn1"
android:textSize="18dip"
android:textColor="#ffffff"
android:layout_marginTop="20dip"
android:onClick="btnMyTracksOnClick">
</Button>
<Button android:id="@+id/btn2"
android:layout_height="wrap_content"
android:layout_width="250dip"
android:drawableLeft="@drawable/img_small_btn_look_around"
android:background="@drawable/main_long_menu_button"
android:text="@string/btn2"
android:textSize="18dip"
android:textColor="#ffffff"
android:layout_marginTop="20dip"
android:layout_below="@+id/btn1">
</Button>
<Button android:id="@+id/btn3"
android:layout_height="wrap_content"
android:layout_width="250dip"
android:drawableLeft="@drawable/img_small_btn_look_around"
android:background="@drawable/main_long_menu_button"
android:text="@string/btn3"
android:textSize="18dip"
android:textColor="#ffffff"
android:layout_marginTop="20dip"
android:layout_below="@+id/btn2">
</Button>
<Button android:id="@+id/btn4"
android:layout_height="wrap_content"
android:layout_width="250dip"
android:drawableLeft="@drawable/img_small_btn_look_around"
android:background="@drawable/main_long_menu_button"
android:text="@string/btn4"
android:textSize="18dip"
android:textColor="#ffffff"
android:layout_marginTop="20dip"
android:layout_below="@+id/bt3">
</Button>
</RelativeLayout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="5dip"
android:layout_alignParentBottom="true">
<Button android:layout_width="90dip"
android:layout_height="wrap_content"
android:textSize="20dip"
android:textColor="#ffffff"
android:layout_alignParentLeft="true"
android:background="@drawable/sett_menu_button"
android:text="@string/back"
android:layout_marginLeft="3dip"/>
</RelativeLayout>
</RelativeLayout>
解决方案
Try changing
<RelativeLayout android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical"
android:layout_below="@+id/logoLayout">
Button 1
Button 2
Button 3
Button 4
</RelativeLayout>
to:
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical"
android:layout_below="@+id/logoLayout">
<!-- example button -->
<Button android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_weight="1"></Button>
</LinearLayout>
the layout_weight should evenly space it out
Hope it works
这篇关于RelativeLayout的高度,以填补剩余空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文