2011-09-23 29 views
2

所有可用的空間,我想是這樣的:使一個組件填補屏幕

enter image description here

但我不知道該如何調整的TextView因此它的屏幕上的所有可用空間,這是不由EditText或Buttons提供。我可以在代碼或xml中執行它嗎?

在XML我試圖把TextView放入FrameLayout,但它沒有區別。目前看起來像:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 

    <FrameLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content"> 

     <TextView 
      android:id="@+id/consola" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:scrollbars = "vertical" 
      android:text="@string/hello"/> 

    </FrameLayout> 

    <EditText 
     android:id="@+id/comando" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content"/> 

    <LinearLayout 
    android:orientation="horizontal" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"> 

     <Button 
      android:text="Conectar" 
      android:id="@+id/boton_conectar" 
      android:layout_width="wrap_content" 
      android:layout_weight="0.5" 
      android:layout_height="wrap_content"> 
     </Button> 
     <Button 
      android:text="Enviar" 
      android:id="@+id/boton_enviar" 
      android:layout_width="wrap_content" 
      android:layout_weight="0.5" 
      android:layout_height="wrap_content"> 
     </Button> 
    </LinearLayout> 
</LinearLayout> 

在代碼我只是檢查按鈕是否與聽衆推送。其中一個按下時,在EditText上獲取文本,並將其附加到TextView。它工作,並且TextView變得更高,而EditText和Buttons減少一行。如果我繼續追加行,最終的EditText和Buttons會跳出屏幕。我想避免這種行爲,並完成將這3個小部件粘貼到屏幕的底部。

+0

什麼@dmon說,再加上你可能想要查看[相對佈局](http://developer.android.com/resources/tutorials/views/hello-relativelayout.html)以平滑您的視圖層次結構 - Eclipse中的Android UI構建器越來越擅長猜測如何定位事物,還要檢查相對佈局支持的XML屬性。 –

回答

2

使用android:layout_weight=1屬性,如窗體底部的按鈕。這將爲它分配大部分空間,剩下的任何元素都留給它。

0

嘗試android:fillViewport =「true」。

2

這都是關於重量。這應該給你想要的東西:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
    <TextView android:text="TextView" 
     android:id="@+id/textView1" 
     android:layout_weight="1" 
     android:layout_width="match_parent" 
     android:layout_height="0dp"> 
    </TextView> 
    <EditText android:id="@+id/editText1" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 
     <requestFocus></requestFocus> 
    </EditText> 
    <LinearLayout android:id="@+id/linearLayout1" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 
     <Button android:text="Button" 
      android:id="@+id/button1" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:layout_width="0dp"> 
     </Button> 
     <Button android:text="Button" 
      android:id="@+id/button2" 
      android:layout_height="wrap_content" 
      android:layout_width="0dp" 
      android:layout_weight="1"> 
     </Button> 
    </LinearLayout> 
</LinearLayout> 

(旁註:當使用重量,相應的高度/寬度設置爲0dp有時會周圍的一些怪異的行爲。)