小妹请教一个LinearLayout布局问题!
请求一个布局的写法。大概描述是这样的!
总体是一个LinearLayout包含三个LinearLayout。
分三层。
第一个LinearLayout要始终在顶部。
第二个LinearLayout要在中间。
中间的这个LinearLayout肯定要包含其它布局,例如放一个ListView,能上下滑动。而不盖住第三个LinearLayout。
第三个LinearLayout要始终在底部。
|------------------------|
| button button | <--第一个LinearLayout
|------------------------|
| |
| 只在此区域内可以 | <--第二个LinearLayout
| 上下滑动,而不影响 |
| 其它布局 |
|------------------------|
| button button | <--第三个LinearLayout
|------------------------|
大概描述是这样的请各位前辈指教!如果有其它好的思路方法也可以告知我。
谢谢。
以下是我写的,请指教
- XML code
<?xml version="1.0" encoding="utf-8"?><LinearLayout android:id="@+id/widget" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" xmlns:android="http://schemas.android.com/apk/res/android"> <LinearLayout android:id="@+id/widget1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal"> <Button android:id="@+id/btnSelect1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="查询" /> </LinearLayout> <LinearLayout android:id="@+id/widget2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal"> <Button android:id="@+id/btnSelect2" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="查询" /> </LinearLayout> <LinearLayout android:id="@+id/widget3" android:gravity="bottom" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal"> <Button android:id="@+id/btnSelect3" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="查询" /> </LinearLayout></LinearLayout>
[解决办法]
如果你要只在此区域内,上下滑动,而不影响其它布局的话,我建议要把中间布局固定大小!比如高多少,宽可以fill_parent
[解决办法]
[解决办法]
如果你想把上面linearLayout和下面的LinearLayout分别固定在上部和下部,那你就在把整体的linearLayout换成RelativeLayout,然后在相应的上下linearlayout中分别设定那个对其上下的属性就ok了
[解决办法]
[解决办法]
RelativeLayout
里面有相对父窗口的布局,只要在你子窗口里加上两个属性就可以相对于父窗口布局了
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
[解决办法]
在你的xml基础上修改的:
- Java code
<?xml version="1.0" encoding="utf-8"?><RelativeLayout android:id="@+id/widget" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"> <LinearLayout android:id="@+id/layout_top" android:layout_width="fill_parent" android:layout_height="wrap_content" [color=#FF0000]android:layout_alignParentTop="true" android:layout_alignParentLeft="true"[/color] android:background="#ffff0000" > <Button android:id="@+id/btnSelect1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="查询" /> </LinearLayout> <LinearLayout android:id="@+id/layout_bottom" android:layout_width="fill_parent" android:layout_height="wrap_content" [color=#FF0000]android:layout_alignParentBottom="true" android:layout_alignParentLeft="true"[/color] android:background="#ff00ff00" > <Button android:id="@+id/btnSelect2" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="查询" /> </LinearLayout> <LinearLayout android:id="@+id/layout_center" android:gravity="bottom" android:layout_width="fill_parent" android:layout_height="fill_parent" [color=#FF0000]android:layout_alignParentLeft="true" android:layout_above="@id/layout_bottom" android:layout_below="@id/layout_top"[/color] android:background="#ff0000ff" > <Button android:id="@+id/btnSelect3" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="查询" /> </LinearLayout></RelativeLayout>