2011-10-11 27 views
0

我想下面布局的活动:android布局:如何写这个?

top button 
middle(scroll view) 
bottom button 

我想底部按钮连接到活动视图的底部,中间部分占据的空间的其余部分。

我如何写布局xml文件?

下面不工作:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" android:layout_height="fill_parent"> 
    <LinearLayout android:focusable="true" 
     android:focusableInTouchMode="true" android:layout_width="0px" 
     android:layout_height="0px" /> 

    <LinearLayout android:orientation="vertical" 
     android:layout_width="fill_parent" android:weightSum="1" android:layout_height="wrap_content"> 

     <LinearLayout android:orientation="horizontal" 
      android:layout_width="fill_parent" android:layout_height="wrap_content" 
      android:weightSum="1"> 
      <EditText android:id="@+id/edit_search" 
       android:layout_width="wrap_content" android:layout_height="wrap_content" 
       android:lines="1" android:hint="发微博内容" android:layout_weight="0.9" /> 
      <Button android:layout_height="wrap_content" android:text="Search" 
       android:layout_width="wrap_content" android:id="@+id/search_btn" 
       android:layout_weight="0.1"></Button> 
     </LinearLayout> 

     <TextView android:layout_width="fill_parent" 
      android:layout_height="wrap_content" android:id="@+id/TextView01" 
      android:paddingTop="5dip" /> 
     <ListView android:layout_width="fill_parent" 
      android:id="@+id/lv01" android:layout_height="390dp"> 
     </ListView> 
     <Button android:id="@+id/create_new_btn" 
     android:layout_height="wrap_content" android:text="我要评论" android:layout_gravity="bottom" 
     android:layout_width="fill_parent"></Button> 
    </LinearLayout> 

</LinearLayout> 

回答

2

对于这种情况,只取RelativeLayout的,其对于这种情况更好,你不需要采取任何子布局。

只需尝试一次,并在此处发布XML布局以进一步改进。

从你的XML布局代码,我可以假设,你只是想有:

的EditText +按钮=>顶, 的TextView +的ListView =>中东, 新建按钮=>底部,

是这种情况?

+0

是的,这是事实。 –

0
<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
    <Button android:id="@+id/button1" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="Button" android:layout_alignParentTop="true" android:layout_alignParentLeft="true"></Button> 
    <Button android:id="@+id/button2" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="Button" android:layout_alignParentBottom="true" android:layout_alignParentLeft="true"></Button> 
    <ScrollView android:id="@+id/scrollView1" android:layout_height="wrap_content" android:layout_width="match_parent" android:layout_below="@+id/button1" android:layout_above="@+id/button2"> 
     <LinearLayout android:id="@+id/linearLayout1" android:layout_width="match_parent" android:layout_height="match_parent"></LinearLayout> 
    </ScrollView>   
</RelativeLayout> 

我认为类似的东西会起作用。该布局中的重要部分是android:layout_belowandroid:layout_above。您可以用其他布局(如ListView)替换ScrollView,并且它将保持在第一个按钮之下并且高于第二个按钮,而不管其大小如何。同样,这些按钮的属性android:layout_alignParentTop="true"android:layout_alignParentBottom="true"将分别保持在RelativeView的顶部和底部。

0

保持简单,顺应LinearLayout中,发挥与权重:

<LinearLayout 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
    <Button 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_weight="0"> 
    </Button> 
    <ScrollView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_weight="1"> 
    <!-- Stuff in scroll view --> 
    </ScrollView> 
    <Button 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_weight="0"> 
    </Button> 
</LinearLayout> 
0

@ParashMayani是正确的..

下面是执行:

<LinearLayout android:focusable="true" 
    android:focusableInTouchMode="true" android:layout_width="fill_parent" 
    android:layout_height="wrap_content" android:id="@+id/relLayout" android:orientation="horizontal" > 



     <EditText android:id="@+id/edit_search" 
      android:layout_width="wrap_content" android:layout_height="wrap_content" 
      android:lines="1" android:hint="Hello" android:layout_weight="0.7"/> 

      <Button android:layout_height="wrap_content" android:text="Search" 
      android:layout_weight="0.3" android:layout_width="wrap_content" android:id="@+id/search_btn" /> 

    </LinearLayout> 

    <TextView android:layout_width="fill_parent" 
     android:layout_height="wrap_content" android:id="@+id/TextView01" 
     android:paddingTop="5dip" android:layout_below="@id/relLayout"/> 

     <Button android:id="@+id/create_new_btn" 
    android:layout_height="wrap_content" android:text="我要评论" android:layout_gravity="bottom" 
    android:layout_width="fill_parent" android:layout_alignParentBottom="true"/> 


    <ListView android:layout_width="fill_parent" 
     android:id="@+id/lv01" android:layout_height="0dp" android:layout_above="@id/create_new_btn" android:layout_below="@id/TextView01" /> 

+0

@Bin Chen:这个工作适合你吗? –