2010-10-13 74 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>