gpt4 book ai didi

android - 使 View 宽度 wrap_content,但重量不超过 0.5

转载 作者:太空宇宙 更新时间:2023-11-03 13:30:45 25 4
gpt4 key购买 nike

在我的 LinearLayout 中,我有两个子 ViewGroup,基本上我希望它们每个占用 50% 的空间(已经完成),但也有可能其中一个 ViewGroup 的内容比 50% 小得多,在这种情况下,有没有办法让第二个 View 与剩余空间相匹配?

现在我的布局是这样的:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:orientation="horizontal"
android:weightSum="1">

<include layout="@layout/layout1"
android:layout_width="0dip"
android:layout_weight="0.5"
android:layout_height="match_parent" />

<include layout="@layout/layout2"
android:layout_width="0dip"
android:layout_weight="0.5"
android:layout_height="match_parent" />

而我想要实现的是:第一个布局wrap_content,但不超过50%,第二个布局填充剩余空间。

提前致谢!

最佳答案

在线性布局中创建两个布局,并为每个布局指定 0.5layout_weight。然后在每一个中放置一个具有特征 android:layout_width="wrap_content" 的 View 组。因此——

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:orientation="horizontal"
android:weightSum="1">
<LinearLayout
android:layout_weight="0.5"
......
<include layout="@layout/layout1"
android:layout_width="wrap_content"
android:layout_height="match_parent" />
</LinearLayout>
<LinearLayout
android:layout_weight="0.5"
......
<include layout="@layout/layout2"
android:layout_width="0dip"
android:layout_weight="0.5"
android:layout_height="match_parent" />
<LinearLayout/>

关于android - 使 View 宽度 wrap_content,但重量不超过 0.5,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13663153/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com