将右 LinearLayout 向右对齐并填充左 LinearLayout [已关闭]

Align Right LinearLayout to right and fill left LinearLayout [closed]

提问人:chriswaddle 提问时间:4/23/2020 最后编辑:Ryan Mchriswaddle 更新时间:4/17/2021 访问量:82

问:


想改进这个问题吗?通过编辑这篇文章添加详细信息并澄清问题。

3年前关闭。

我有一个简单的问题。 我想在附图中执行此操作:

descripted my problem

如何保护我的 LinearLayout?

多谢

安卓 XML

评论


答:

1赞 Fred 4/23/2020 #1

这很容易。 您可以使用 weightSum 填充剩余空间。 检查下面的代码。

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:weightSum="10">

    <LinearLayout           // This is First LinearLayout.
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="5"/>

    <LinearLayout           // This is Remaining Space.
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="2"/>

    <LinearLayout           // This is Second LinearLayout what you want to put right.
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="3"/>
</LinearLayout>

请记住,layout_weight 的所有值总和都应与 weightSum 相同。 希望它会有所帮助。