带有两个宽度相等的子元素的LinearLayout

带有两个宽度相等的子元素的LinearLayout,第1张

概述我在使LinearLayout的两个子级具有相同的宽度时遇到一些问题.这就是我得到的:这是我用于灰色框的布局xml:<LinearLayoutandroid:layout_width="fill_parent"android:layout_height="wrap_content"android:orientation="horizontal"android:weightSum="2

我在使linearLayout的两个子级具有相同的宽度时遇到一些问题.这就是我得到的:

这是我用于灰色框的布局xml:

<linearLayout     androID:layout_wIDth="fill_parent"    androID:layout_height="wrap_content"    androID:orIEntation="horizontal"    androID:weightSum="2"    androID:background="@color/medium_grey"    >    <ImageVIEw         androID:ID="@+ID/profile_photo"        androID:layout_wIDth="0dp"        androID:layout_height="wrap_content"        androID:src="@drawable/placeholder_profile_photo"        androID:scaleType="fitCenter"        androID:contentDescription="@string/blank"        androID:layout_weight="1"        />    <linearLayout         androID:layout_wIDth="0dp"        androID:layout_height="wrap_content"        androID:orIEntation="vertical"        androID:gravity="center"        androID:layout_weight="1"        androID:layout_gravity="center_vertical"        androID:background="@color/alert"        >        <TextVIEw            androID:ID="@+ID/profile_rate_header"            androID:layout_wIDth="fill_parent"            androID:layout_height="wrap_content"            androID:text="Rate User"            />        <linearLayout             androID:ID="@+ID/profile_action_rate_user"            androID:layout_wIDth="fill_parent"            androID:layout_height="wrap_content"            androID:orIEntation="horizontal"            androID:layout_weight="1"            androID:gravity="center"            >            <ImageVIEw                 androID:ID="@+ID/profile_action_rate_up"                androID:layout_wIDth="wrap_content"                androID:layout_height="wrap_content"                androID:src="@drawable/user_rate_up"                />            <ImageVIEw                 androID:ID="@+ID/profile_action_rate_down"                androID:layout_wIDth="wrap_content"                androID:layout_height="wrap_content"                androID:src="@drawable/user_rate_down"                />        </linearLayout>    </linearLayout></linearLayout>

我假设设置根linearLayout的子级的layout_weight以及weightSum和宽度0dp会产生所需的效果(图像与粉红色的“ rate user”部分的大小相同),但是事实并非如此.

我想念什么?

编辑:

这就是我想要的样子

照片和粉色线性布局的宽度应相等.

解决方法:

androID:weightSum =“ 2”应该在两个子ImageVIEws的父级上,而不在上级父级上.否则尝试将权重设置为0.5,看看是否可行.

另外,使用此类权重时,两个图像视图的宽度应为androID:layout_wIDth =“ 0dp”.

接下来,按比例放大图像以填充空间.详细资料here.

总结

以上是内存溢出为你收集整理的带有两个宽度相等的子元素的LinearLayout全部内容,希望文章能够帮你解决带有两个宽度相等的子元素的LinearLayout所遇到的程序开发问题。

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

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

原文地址:https://www.54852.com/web/1095097.html

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

发表评论

登录后才能评论

评论列表(0条)

    保存