开发者

How to get three quarters of the fill_parent

开发者 https://www.devze.com 2023-03-23 00:31 出处:网络
I already know that if you have n eleme开发者_如何学JAVAnts with equal heights=fill_parent, they get the same size so they fill the parent among all of them.

I already know that if you have n eleme开发者_如何学JAVAnts with equal heights=fill_parent, they get the same size so they fill the parent among all of them.

But I would like to have, for example a component 1/4 of the screen height, and another component 3/4. How can that be done?


You should use a linear layout to do this

Use layout_weight to manipulate the ratio of fill.

<?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">

    <TextView android:id="@+id/component1" android:text="hello"
        android:layout_width="fill_parent" android:layout_weight="0.25" />

    <TextView android:id="@+id/component2" android:text="world"
        android:layout_width="fill_parent" android:layout_weight="0.75" />

</LinearLayout>

You can also have the values as 1.0 and 3.0 respectively, just so long as the ratio is correct.

0

精彩评论

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