2011-12-15 142 views
0

我想做出如下所示的内容。但由于某种原因,这些按钮是不可见的。谁能好心帮在android中布局的隐形元素

-------------------- 
txt1   txt2 
-------------------- 
|     | 
|     | 
|     | 
|  txtview1  | 
|     | 
|     | 
|     | 
-------------------- 
|btn1|  |btn2| 
-------------------- 

布局代码:

     <?xml version="1.0" encoding="utf-8"?> 

      <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:orientation="vertical" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent"> 

       <TextView 
        android:id="@+id/txt1" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"    
        android:text="Network Status:  "/> 

       <TextView 
        android:id="@+id/txt2" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="updating..." 
        android:layout_toRightOf="@+id/txt1"/> 

       <ScrollView 
        android:id="@+id/sv1" 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" 
        android:layout_below="@id/txt1"> 

        <TextView 
         android:id="@+id/txt3" 
         android:layout_width="fill_parent" 
         android:layout_height="fill_parent" 
         android:text="Log"/> 

       </ScrollView> 

       <Button 
        android:id="@+id/btn1" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="Start" 
        android:layout_below="@+id/sv1"/> 

       <Button 
        android:id="@+id/btn2" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="Stop" 
        android:layout_toRightOf="@+id/btn1" 
        android:layout_below="@+id/sv1"/> 


      </RelativeLayout> 
+0

尝试使用LinearLayout作为您的ScrollView的环境... – WarrenFaith 2011-12-15 23:40:37

回答

2
选项

问题是,ScrollView会填满剩下的空间。你可以使用fill_parent属性,但ScrollView必须是以上的这些按钮。因此在ScrollView中,将layout_above设置为其中一个按钮。

1

你需要的,如果你使用的RelativeLayout使用您的元素定位属性

会有像android:layout_alignParentTop="true"android:layout_below="@id/yourelement

+0

好吧,如果我给`android:layout_alignParentTop =“true”`然后,我看到按钮,但它们在顶部。如果我使用`android:layout_alignParentBottom =“true”`,这些按钮是不可见的!..任何建议? – Ahsan 2011-12-15 23:51:20

+0

设置为`fill_parent`的scrollview是做什么的。使宽度填充父级,但高度需要现在是别的 – CQM 2011-12-15 23:54:42