Android百分比宽度布局

Android百分比宽度布局,第1张

概述我需要将视图的宽度设置为屏幕宽度的50%,然后将此视图水平居中,同时可能有一个或多个按钮,这些按钮可以显示为附加到屏幕的左侧或右侧. 我正在使用相对布局,这样我就可以放置一个带有权重的线性布局,使我的50%居中,同时将任何按钮放在连接到RL左边或右边的LL的顶部.但是这个布局缺少蓝色中间栏.如果我将中间视图layout_weight设置为1,我将获得3个相同大小的条形图. <RelativeLay 我需要将视图的宽度设置为屏幕宽度的50%,然后将此视图水平居中,同时可能有一个或多个按钮,这些按钮可以显示为附加到屏幕的左侧或右侧.

我正在使用相对布局,这样我就可以放置一个带有权重的线性布局,使我的50%居中,同时将任何按钮放在连接到RL左边或右边的LL的顶部.但是这个布局缺少蓝色中间栏.如果我将中间视图layout_weight设置为1,我将获得3个相同大小的条形图.

<relativeLayout    androID:layout_wIDth="match_parent"    androID:layout_height="48dp">    <linearLayout        androID:ID="@+ID/stupID_androID"        androID:orIEntation="horizontal"        androID:layout_wIDth="match_parent"        androID:layout_height="match_parent" >        <VIEw            androID:layout_wIDth="fill_parent"            androID:layout_height="match_parent"            androID:background="#FF0000"            androID:layout_weight="1" />        <VIEw            androID:layout_wIDth="fill_parent"            androID:layout_height="match_parent"            androID:background="#0000FF"            androID:layout_weight="2" />        <VIEw            androID:layout_wIDth="fill_parent"            androID:layout_height="match_parent"            androID:background="#00FF00"            androID:layout_weight="1" />    </linearLayout></relativeLayout>
解决方法 您应该将视图的宽度设置为0dip
<relativeLayout    androID:layout_wIDth="match_parent"    androID:layout_height="48dp">    <linearLayout        androID:ID="@+ID/stupID_androID"        androID:orIEntation="horizontal"        androID:layout_wIDth="match_parent"        androID:layout_height="match_parent" >        <VIEw            androID:layout_wIDth="0dip"            androID:layout_height="match_parent"            androID:background="#FF0000"            androID:layout_weight="1" />        <VIEw            androID:layout_wIDth="0dip"            androID:layout_height="match_parent"            androID:background="#0000FF"            androID:layout_weight="2" />        <VIEw            androID:layout_wIDth="0dip"            androID:layout_height="match_parent"            androID:background="#00FF00"            androID:layout_weight="1" />    </linearLayout></relativeLayout>
总结

以上是内存溢出为你收集整理的Android百分比宽度布局全部内容,希望文章能够帮你解决Android百分比宽度布局所遇到的程序开发问题。

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

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

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

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

发表评论

登录后才能评论

评论列表(0条)

保存