简体   繁体   English

是否有可能获得一个线性布局来填充父屏幕的 50%?

[英]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_gravity="center" android:layout_height="fill_parent">

I want to make it fill 50% of the android screen instead of the 200dp我想让它填满 android 屏幕的 50% 而不是 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.将您的线性布局包装在另一个线性布局中,您已将 weightsum 设置为 100。然后将子线性布局的 layout_weight 设置为 50,它将占据屏幕的 50%。 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.每个内部线性布局将占据屏幕的 50%。

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...如果是这样,您在屏幕中是否还有其他组件?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM