开发者

Is it possible to get a linearlayout to fill 50% of the parent screen?

   <LinearLayout
    android:orientation="vertical"
    android:layout_margin="10dp"
    android:paddingTop="35dp"
    android:layout_width="200dp"
    android:layout_grav开发者_Go百科ity="center" android:layout_height="fill_parent">

I want to make it fill 50% of the android screen instead of the 200dp


Wrap your linearlayout in another linearlayout where you've set the weightsum to 100. Then set the layout_weight of the child linearlayout to 50 and it will take up 50% of the screen. Like this:

<?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" android:weightSum="100">

    <LinearLayout android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="50">
</LinearLayout>
<LinearLayout android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="50">
</LinearLayout>


Use the linear layout within another linear layout like this

<LinearLayout 
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent" 
        android:layout_weight="1.0"
        > <!-- This will have 50% of the screen --> </LinearLayout>
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent" 
        android:layout_weight="1.0">  <!-- This will have another 50% of the screen --> </LinearLayout>
</LinearLayout>

Each of the inner linear layouts will occupy 50% of the screen.


did you have any other components in the screen if so wrap them all in a single linearlayout and give both layouts equal layout_weight... hopefully this will help you...

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜