android–RelativeLayout重量

android–RelativeLayout重量,第1张

概述在布局资源XML中,我有3个RelativeLayout(s),它们位于主RelativeLayout中.视图将垂直显示.这3个RelativeLayout()彼此相邻设置,我想让它们填满整个屏幕,无论屏幕大小是多少.我的布局视图:<RelativeLayoutxmlns:android="http://schemas.android.com/apkes/android"xmlns:tools=

在布局资源XML中,我有3个relativeLayout(s),它们位于主relativeLayout中.视图将垂直显示.这3个relativeLayout()彼此相邻设置,我想让它们填满整个屏幕,无论屏幕大小是多少.我的布局视图:

<relativeLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"xmlns:tools="http://schemas.androID.com/tools"androID:layout_wIDth="match_parent"androID:layout_height="match_parent"androID:background="@drawable/backg" ><ImageVIEw    androID:ID="@+ID/imageVIEw1"    androID:layout_wIDth="wrap_content"    androID:layout_height="wrap_content"    androID:layout_alignParentleft="true"    androID:layout_alignParenttop="true"    androID:layout_margintop="@dimen/top_mr_image"    androID:src="@drawable/temp" /><relativeLayout    androID:ID="@+ID/r1"    androID:layout_wIDth="0dp"    androID:layout_height="wrap_content"    androID:layout_alignParentBottom="true"    androID:layout_alignParentleft="true"    androID:layout_below="@+ID/imageVIEw1"    androID:layout_marginleft="10dp"    androID:background="@drawable/r1bg"    androID:layout_weight="1"     >    <TextVIEw        androID:ID="@+ID/textVIEw1"        androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content"        androID:layout_alignParentleft="true"        androID:layout_marginleft="@dimen/txt_mr_right"        androID:layout_marginRight="@dimen/txt_mr_right"        androID:layout_margintop="39dp"        androID:text="S"        androID:textAppearance="?androID:attr/textAppearanceLarge" />    <TextVIEw        androID:ID="@+ID/textVIEw2"        androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content"        androID:layout_alignParentleft="true"        androID:layout_below="@ID/textVIEw1"        androID:layout_marginleft="@dimen/txt_mr_right"        androID:layout_marginRight="@dimen/txt_mr_right"        androID:text="T"        androID:textAppearance="?androID:attr/textAppearanceLarge" /></relativeLayout>    <relativeLayout        androID:ID="@+ID/r2"        androID:layout_wIDth="0dp"        androID:layout_height="wrap_content"        androID:layout_alignParentBottom="true"        androID:layout_aligntop="@+ID/r1"        androID:layout_toRightOf="@+ID/r1"        androID:layout_weight="1" >    </relativeLayout>            <relativeLayout        androID:ID="@+ID/r3"        androID:layout_wIDth="0dp"        androID:layout_height="wrap_content"        androID:layout_alignParentBottom="true"        androID:layout_aligntop="@+ID/r2"        androID:layout_toRightOf="@+ID/r2"        androID:layout_weight="1" >    </relativeLayout>

我为每个relativeLayout设置了weight = 1和layout_wIDth = 0dp,这个技术适用于按钮,我认为与relativeLayout相同,似乎我的想法是错误的.任何想法?

UPD1:我添加了一张我想要的图像

解决方法:

relativeLayout不注意androID:layout_weight. (这是LinearLayout.LayoutParams的财产,但不是RelativeLayout.LayoutParams的财产.)

您应该能够通过更简单的视图层次结构获得所需的布局.目前尚不清楚你要做什么,因为最后两个relativeLayouts是空的.如果你需要一个纯粹的垂直组织,我建议使用linearLayout而不是relativeLayout.

编辑根据您的编辑,您看起来想要三个复合视图的水平布局,每个视图都可单击.我认为以下内容可行:

<linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"    androID:orIEntation="horizontal"    androID:layout_wIDth="match_parent"    androID:layout_height="match_parent"    >    <!-- First column -->    <linearLayout        androID:ID="@+ID/firstColumn"        androID:orIEntation="vertical"        androID:gravity="center_horizontal"        androID:layout_wIDth="0dp"        androID:layout_height="match_parent"        androID:layout_weight="1"        >        <ImageVIEw            androID:layout_wIDth="wrap_content"            androID:layout_height="wrap_content"            androID:src="..." />        <TextVIEw            androID:layout_wIDth="wrap_content"            androID:layout_height="match_parent"            androID:text="text 1"            . . . />    </linearLayout>    <!-- Second column -->    <linearLayout . . . >        . . .    </linearLayout></linearLayout>

如果按钮的内容不正确,您可以使用relativeLayout替换二级linearLayout视图,如果这有助于更好地组织布局.

总结

以上是内存溢出为你收集整理的android – RelativeLayout重量全部内容,希望文章能够帮你解决android – RelativeLayout重量所遇到的程序开发问题。

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

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

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

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

发表评论

登录后才能评论

评论列表(0条)

保存