2010-10-13 90 views
1

我在Android上非常新。TextView填充了80%的屏幕

我想將一個TextView放入一個LinearLayout中,填充LinearLayout的80%的高度。

我該怎麼做?或者如何在Widht和高度上分配百分比?

謝謝。

回答

3

像這樣的佈局將起作用。關鍵是layout_weight屬性。 Android的文檔對於該屬性並不是很好。請注意,第二個TextView(可以是任何東西)是必需的,否則第一個TextView將佔用整個空間。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
> 
    <TextView android:layout_weight="0.8" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/hello" 
    android:background="#FFC300" 
    /> 
    <TextView android:layout_weight="0.2" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="second text box" 
    /> 
</LinearLayout>