android – 对齐左边缘到中心 – RelativeLayout

android – 对齐左边缘到中心 – RelativeLayout,第1张

概述我有以下要求(大大简化了): 文本2必须从屏幕的CENTER开始. 我只能使用LinearLayout来实现: <more_code></more_code><LinearLayout android:baselineAligned="false" and 我有以下要求(大大简化了):

文本2必须从屏幕的CENTER开始.

我只能使用linearLayout来实现:

<more_code></more_code><linearLayout                                    androID:baselineAligned="false"                                    androID:weightSum="2"                                    androID:layout_wIDth="match_parent"                                    androID:layout_height="wrap_content">                                <linearLayout                                        androID:layout_weight="1"                                        androID:orIEntation="horizontal"                                        androID:layout_wIDth="0dp"                                        androID:layout_height="wrap_content">                                    <TextVIEw                                            androID:layout_wIDth="wrap_content"                                            androID:layout_height="wrap_content"                                            androID:text="test one"/>                                    <TextVIEw                                            androID:layout_wIDth="wrap_content"                                            androID:layout_height="wrap_content"                                            androID:text="test two"/>                                </linearLayout>                                <linearLayout                                        androID:layout_weight="1"                                        androID:orIEntation="horizontal"                                        androID:layout_wIDth="0dp"                                        androID:layout_height="wrap_content">                                    <TextVIEw                                            androID:layout_wIDth="wrap_content"                                            androID:layout_height="wrap_content"                                            androID:text="test three"/>                                    <TextVIEw                                            androID:layout_wIDth="wrap_content"                                            androID:layout_height="wrap_content"                                            androID:text="test four"/>                                </linearLayout>                            </linearLayout><more_code></more_code>

因为我已经有太多的嵌套视图(因此得到一个myfile.xml有更多的10个级别,不好的性能警告)我想知道如果我可以得到与一个relativeLayout相同的结果.我一直在documentation,但我找不到一个允许我的财产.

解决方法 如果您将0dp作为开销接受0dp的1个空视图,这很简单.在我看来,这比嵌套的观点更好,但这可以作为其他观点的参考.

使用空的空格(0x0像素).如果你把这个空间水平定位,你可以用它作为参考:

<relativeLayout>    <!-- Empty layout (0x0 dp) centered horizontally -->    <Space androID:ID="@+ID/dummy"         androID:layout_wIDth="0dp"         androID:layout_height="0dp"        androID:layout_centerHorizontal="true"         androID:visibility="invisible"/>    <!-- Align to parent left -->    <TextVIEw        androID:ID="@+ID/test_one"        androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content"        androID:layout_alignParentleft="true"        androID:text="test one"/>    <!-- to right of the prevIoUs one,and to left of the dummy -->    <TextVIEw        androID:ID="@+ID/test_two"        androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content"        androID:layout_toRightOf="@+ID/test_one"        androID:layout_toleftOf="@+ID/dummy"        androID:text="test two"/>    <!-- Align to right of the dummy -->    <TextVIEw        androID:ID="@+ID/test_three"        androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content"        androID:layout_toRightOf="@+ID/dummy"        androID:text="test three"/>    <!-- Align to right of the prevIoUs one,and parent right -->    <TextVIEw        androID:ID="@+ID/test_four"        androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content"        androID:layout_toRightOf="@+ID/test_three"        androID:layout_alignParentRight="true"        androID:text="test four"/></relativeLayout>
总结

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

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

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

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

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

发表评论

登录后才能评论

评论列表(0条)

    保存