Android layout 如何让安卓布局重量发挥作用?

Android layout 如何让安卓布局重量发挥作用?,android-layout,android-layout-weight,Android Layout,Android Layout Weight,我对Android的布局缩放/定位非常失望。我无法让操作系统正确地“权衡”我的布局。基本布局是线性布局,子布局的权重设置正确。但当它运行时,这些比例并没有保持。例如: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation

我对Android的布局缩放/定位非常失望。我无法让操作系统正确地“权衡”我的布局。基本布局是线性布局,子布局的权重设置正确。但当它运行时,这些比例并没有保持。例如:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#38921c">

    <LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="0px"
    android:layout_weight="0.1"
    android:orientation="vertical"
    android:layout_centerVertical="true">

…(省略视图)


…(省略视图)



当我运行此操作时,屏幕(平板电脑和手机)给第二个(0.2重量)布局留出了太多的空间,并将下面的布局压缩到太小的空间。关于使用布局重量进行适当缩放,我遗漏了什么?谢谢。

android:layout\u weight
用于指定多个视图之间的大小比率

在本例中,您似乎有多个视图。在您决定了应该为每个视图分配多少百分比的屏幕后,您可以设置它

示例:您想将屏幕分为3个部分,分别为2/10、3/10和5/10(屏幕的一半),然后按2、3、5的顺序排列权重。(例如android:layout_weight=“2”)


重要提示:要使其正常工作,还必须将高度或宽度(取决于方向)设置为0px。否则,所有重量测量都将被视为垃圾。

我很感激您的回答,但正如您在我发布的代码中所看到的,我已经设置了百分比(0.1、0.2、0.7),并将布局高度设置为0。它没有像广告宣传的那样工作。相反,先尝试使用1、2、7,还有一种叫做android:weightSum=“”的东西用于主布局。您可以看到带有演示的链接:
    </LinearLayout>

    <LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="0px"
    android:layout_weight="0.2"
    android:orientation="vertical"
    android:layout_centerVertical="true">
            <ImageView
        android:id="@+id/imageView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/zero" />

            <ImageView
        android:id="@+id/imageView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/zero" />

    </LinearLayout>

    <LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="0px"
    android:layout_weight="0.7"
    android:orientation="vertical"
    android:layout_centerVertical="true">
    </LinearLayout>
</LinearLayout>