开发者

TextView fills the 80% of the screens

I'm very very new on Android.

I want to put a TextView inside a LinearLayout that fills the 80% of LinearLayout's height.

开发者_运维问答

How can I do that? or How can assign percentage on Widht and Height?

Thanks.


A layout like this will work. The key is the layout_weight attribute. Android's documentation is not very good for that attribute. Note that the second TextView (it could be anything) is required otherwise, the first TextView will take up the whole space.

<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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜