无法正确使用android:weightSum

无法正确使用android:weightSum,android,android-layout,Android,Android Layout,我正在尝试建立一个布局。代码如下。 我无法为布局添加适当的权重。下面的代码不会创建带有权重的布局。无论是否添加权重,布局都是相同的! 如果我没有解释清楚,请原谅。我对编程一无所知 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" and

我正在尝试建立一个布局。代码如下。 我无法为布局添加适当的权重。下面的代码不会创建带有权重的布局。无论是否添加权重,布局都是相同的! 如果我没有解释清楚,请原谅。我对编程一无所知

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="100" >

<ScrollView
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_weight="30" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="TextView" />

        <EditText
            android:id="@+id/editText1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ems="10" >
        </EditText>

        <TextView
            android:id="@+id/textView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="TextView" />

        <EditText
            android:id="@+id/editText2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ems="10" />

        <TextView
            android:id="@+id/textView3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="TextView" />

        <EditText
            android:id="@+id/editText3"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ems="10" />

        <TextView
            android:id="@+id/textView4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="TextView" />

        <EditText
            android:id="@+id/editText4"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ems="10" />

        <TextView
            android:id="@+id/textView5"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="TextView" />

        <EditText
            android:id="@+id/editText5"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ems="10" />

        <TextView
            android:id="@+id/textView6"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="TextView" />

        <EditText
            android:id="@+id/editText6"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ems="10" />
    </LinearLayout>
</ScrollView>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="fill_parent"
    android:layout_weight="40"
    android:orientation="vertical" >

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button" />
</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="fill_parent"
    android:layout_weight="30"
    android:orientation="vertical" >

    <AnalogClock
        android:id="@+id/analogClock1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
</LinearLayout>


布局权重
机制按照子权重的比例分配布局中的任何剩余空间。您的视图已经占用了
fill\u parent
的所有空间,因此没有剩余空间供权重机制分配。将加权布局子项高度设置为0px,以便实际上有一些空间可以按权重分布


此外,指定权重和通常是多余的。布局本身可以为您计算子权重的总和。

layout\u weight
机制会按子权重的比例分配布局中的所有剩余空间。您的视图已经占用了
fill\u parent
的所有空间,因此没有剩余空间供权重机制分配。将加权布局子项高度设置为0px,以便实际上有一些空间可以按权重分布


此外,指定权重和通常是多余的。布局本身可以为您计算子权重的总和。

layout\u weight
机制会按子权重的比例分配布局中的所有剩余空间。您的视图已经占用了
fill\u parent
的所有空间,因此没有剩余空间供权重机制分配。将加权布局子项高度设置为0px,以便实际上有一些空间可以按权重分布


此外,指定权重和通常是多余的。布局本身可以为您计算子权重的总和。

layout\u weight
机制会按子权重的比例分配布局中的所有剩余空间。您的视图已经占用了
fill\u parent
的所有空间,因此没有剩余空间供权重机制分配。将加权布局子项高度设置为0px,以便实际上有一些空间可以按权重分布



此外,指定权重和通常是多余的。布局本身可以为您计算子权重之和。

如果要根据权重设置布局,滚动视图没有权重和属性,请删除滚动视图,否则只需使用滚动视图,您在滚动视图中不需要权重和。

如果要根据权重设置布局,滚动视图没有权重和属性若要加权,请删除滚动视图,否则只需使用滚动视图,您在滚动视图中不需要加权和。

滚动视图没有加权和属性,如果您想根据加权设置布局,请删除滚动视图,否则只需使用滚动视图,您在滚动视图中不需要加权和。

滚动视图没有加权和属性属性如果要根据权重设置布局,请删除滚动视图,否则只需使用滚动视图即可。滚动视图中不需要权重和。

我从未使用过android:weightSum,也从未使用过它。尝试删除它。另外,如果您使用的是重量,您应该使用
0dp
来测量有重量儿童的身高。@Karakuri完全正确。还要注意的是,一次只能“加权”一个维度(宽度或高度)。我从未使用过
android:weightSum
,也从未需要过它。尝试删除它。另外,如果您使用的是重量,您应该使用
0dp
来测量有重量儿童的身高。@Karakuri完全正确。还要注意的是,一次只能“加权”一个维度(宽度或高度)。我从未使用过
android:weightSum
,也从未需要过它。尝试删除它。另外,如果您使用的是重量,您应该使用
0dp
来测量有重量儿童的身高。@Karakuri完全正确。还要注意的是,一次只能“加权”一个维度(宽度或高度)。我从未使用过
android:weightSum
,也从未需要过它。尝试删除它。另外,如果您使用的是重量,您应该使用
0dp
来测量有重量儿童的身高。@Karakuri完全正确。还请注意,您一次只能“加权”一个维度(宽度或高度)。并且,作为补充信息,请注意,自API级别8以来,
fill\u parent
已被弃用。由于API级别为8,您应该使用
match\u parent
来代替。并且,作为补充信息,请注意
fill\u parent
自API级别为8以来已被弃用。由于API级别为8,您应该使用
match\u parent
来代替。并且,作为补充信息,请注意
fill\u parent
自API级别为8以来已被弃用。由于API级别为8,您应该使用
match\u parent
来代替。并且,作为补充信息,请注意
fill\u parent
自API级别为8以来已被弃用。由于API级别为8,您应该使用
match\u parent
。您能更清楚地解释一下吗?这似乎有点不和谐。你能解释清楚一点吗?这似乎有点不和谐。你能解释清楚一点吗?这似乎有点不和谐。你能解释清楚一点吗?它似乎不和谐。