Android layout Android布局权重没有像我想的那样工作

Android layout Android布局权重没有像我想的那样工作,android-layout,Android Layout,跟随 我有这个: <LinearLayout android:layout_width="match_parent" android:layout_height="fill_parent" android:orientation="horizontal" > <Button android:id="@+id/buttonToastSimple" android:layout_width="fill_parent"

跟随

我有这个:

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal" >

    <Button
        android:id="@+id/buttonToastSimple"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="English Toast" />

    <Button
        android:id="@+id/buttonToastFancy"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="3"
        android:text="French Toast" />

</LinearLayout>

链接告诉我ButtonStastFancy将占据屏幕大小的四分之三(3/(3+1),但反过来说,ButtonStastSimple将占据Eclipse/my AVD屏幕大小的四分之三

我做错了什么?


<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="fill_parent"
    android:weightSum="4"
    android:orientation="horizontal" >

    <Button
        android:id="@+id/buttonToastSimple"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="English Toast" />

    <Button
        android:id="@+id/buttonToastFancy"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="3"
        android:text="French Toast" />

</LinearLayout>
尝试将所需属性设置为
0dp


例如,如果要设置宽度支持的权重,请将
android:layout\u width=“0dp”
android:layout\u weight=“3”
一起使用。此外,不要忘记父视图中的
android:weightSum=“4”

视图将占用的空间量计算为 尺寸/布局权重因此布局权重较低的视图在布局中占据更多空间。将来,您可能还需要使用布局权重总和


是的。

这很管用,谢谢。我的'fill\u parent'值发生了什么变化,使它可以反转所有内容?欢迎,如果它管用,请您接受并向上投票。因为fill parent意味着填充可用空间,所以当您将其设置为1且有更多可用空间时,它将占用它,而不是跟随它将宽度值设置为0dp正好解决了我的问题。谢谢!