2011-12-15 45 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