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

android-使视图宽度wrap_content,但重量不超过0.5,第1张

概述在我的LinearLayout中,我有两个子ViewGroup,基本上我希望它们各自占用50%的空间(并且这样做),但是在这种情况下,这些ViewGroup之一的内容可能比50%小得多,有什么方法可以使第二个视图与剩余空间匹配?现在我的布局看起来像这样:<LinearLayoutxmlns:android="http://schemas.android.

在我的linearLayout中,我有两个子VIEwGroup,基本上我希望它们各自占用50%的空间(并且这样做),但是在这种情况下,这些VIEwGroup之一的内容可能比50%小得多,有什么方法可以使第二个视图与剩余空间匹配?

现在我的布局看起来像这样:

<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.5的layout_weight.然后在每个视图组中放入一个具有androID:layout_wIDth =“ wrap_content”特征的视图组.因此 –

<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-使视图宽度wrap_content,但重量不超过0.5全部内容,希望文章能够帮你解决android-使视图宽度wrap_content,但重量不超过0.5所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1086006.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-27
下一篇 2022-05-27

发表评论

登录后才能评论

评论列表(0条)

保存