理解权重和layout_weight,layout_weight越大,布局中的收缩越多.

理解权重和layout_weight,layout_weight越大,布局中的收缩越多.,第1张

概述我试图通过此示例了解重量布局.绝对不是火箭科学.然而,这个例子使…>weightSum决定大小,然后>然后根据LinearLayout中视图的layout_weight值划分布局.在此示例中,我有一个布局,权重为5,然后将其分为两个视图:<LinearLayoutxmlns:android="http://schemas.android.com/apke

我试图通过此示例了解重量布局.

绝对不是火箭科学.然而,这个例子使…

> weightSum决定大小,然后
>然后根据linearLayout中视图的layout_weight值划分布局.

在此示例中,我有一个布局,权重为5,然后将其分为两个视图:

<linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"    androID:layout_wIDth="fill_parent"    androID:layout_height="fill_parent"    androID:background="@color/transactionRowBackground"    androID:paddingBottom="5dp"    androID:paddingtop="5dp" androID:orIEntation="horizontal" >    <linearLayout        androID:layout_wIDth="fill_parent"        androID:layout_height="wrap_content"        androID:orIEntation="vertical" androID:layout_weight="2" >        <TextVIEw            androID:ID="@+ID/Title"            androID:layout_wIDth="fill_parent"            androID:layout_height="fill_parent"            androID:clickable="true"            androID:gravity="top"            androID:padding="5dp"            androID:text="Test Title"            androID:textcolor="@color/textcolor"            androID:textSize="@dimen/subheadingTextSize"            androID:textStyle="bold" />        <TextVIEw            androID:ID="@+ID/description"            androID:layout_wIDth="fill_parent"            androID:layout_height="fill_parent"            androID:clickable="true"            androID:gravity="top"            androID:padding="5dp"            androID:text="This is a test description"            androID:textcolor="@color/textcolor"            androID:textSize="@dimen/normalTextSize" />    </linearLayout>    <ImageVIEw        androID:layout_wIDth="fill_parent"        androID:layout_height="wrap_content"        androID:layout_weight="3"        androID:src="@drawable/ic_launcher"        androID:layout_gravity="top"        androID:contentDescription="" /></linearLayout>

我无法理解的是,我给ImageVIEwer更大的数字是它从父级获得的最小空间.因此,它实际上是如何计算ImageVIEw的大小的.

您可以尝试使用上述xml.如果您将ImageVIEw的布局权重更改为1,并将子linearlayout更改为4,我认为这更有意义,那么将发生相反的情况.

ImageVIEw将扩大,子线性布局将缩小.我认为数字越大,您获得的空间就越大.

解决方法:

由于在最外层布局上您具有androID:orIEntation =“ horizo​​ntal”,因此我相信您想在水平方向上更改ImageVIEw和内部linearLayout所占用的大小/空间.对于这种情况,请尝试使用

androID:layout_wIDth="0dp"

在放置androID:layout_weight的布局上.如果外部布局的方向是垂直的,那么我将使用androID:layout_height =“ 0dp”来使权重能够处理布局的宽度/高度.

<linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"    androID:layout_wIDth="fill_parent"    androID:layout_height="fill_parent"    androID:background="@color/transactionRowBackground"    androID:paddingBottom="5dp"    androID:paddingtop="5dp" androID:orIEntation="horizontal" >    <linearLayout        androID:layout_wIDth="0dp"        androID:layout_height="wrap_content"        androID:orIEntation="vertical" androID:layout_weight="2" >        <TextVIEw            androID:ID="@+ID/Title"            androID:layout_wIDth="fill_parent"            androID:layout_height="fill_parent"            androID:clickable="true"            androID:gravity="top"            androID:padding="5dp"            androID:text="Test Title"            androID:textcolor="@color/textcolor"            androID:textSize="@dimen/subheadingTextSize"            androID:textStyle="bold" />        <TextVIEw            androID:ID="@+ID/description"            androID:layout_wIDth="fill_parent"            androID:layout_height="fill_parent"            androID:clickable="true"            androID:gravity="top"            androID:padding="5dp"            androID:text="This is a test description"            androID:textcolor="@color/textcolor"            androID:textSize="@dimen/normalTextSize" />    </linearLayout>    <ImageVIEw        androID:layout_wIDth="0dp"        androID:layout_height="wrap_content"        androID:layout_weight="3"        androID:src="@drawable/ic_launcher"        androID:layout_gravity="top"        androID:contentDescription="" /></linearLayout>

阅读AndroID文档可能会帮助:Layout Weights

总结

以上是内存溢出为你收集整理的理解权重和layout_weight,layout_weight越大,布局中的收缩越多.全部内容,希望文章能够帮你解决理解权重和layout_weight,layout_weight越大,布局中的收缩越多.所遇到的程序开发问题。

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

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

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

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

发表评论

登录后才能评论

评论列表(0条)

保存