微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

android RelativeLayout,等间距?

我正在使用相对布局来创建一个计算器屏幕,并且我有一排标签为1,2和3的按钮.我希望它们间隔均匀,但我不确定如何使用相对布局

我习惯于在LinearLayout中使用android:layout_weight函数,并给出每个值为android的值:layout_width =“fill_parent”,以及layout_weight =“1”

任何方式可以在计算器屏幕上进行此操作(不指定DP或PX)

这是我现在设置的,它们按照从左到右的顺序排列在TextView(计算器输出画面)下.任何建议/解决方案均匀的空间,填补屏幕的宽度?

<TextView
android:id="@+id/textView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/edit_text"
android:layout_margin="6px"
/>

<Button
android:id="@+id/button1"
android:text="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView"
/>

<Button
android:id="@+id/button2"
android:text="2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView"
android:layout_toRightOf="@+id/button1"/>

<Button
android:id="@+id/button3"
android:text="3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView"
android:layout_toRightOf="@+id/button2"
/>

解决方法

如果你想要相等的间距,你不需要一个RelativeLayout.使用LinearLayout,就像您在问题中建议的那样.如果需要,将Buttons放在LinearLayout中,并将LinearLayout放在RelativeLayout中.

原文地址:https://www.jb51.cc/android/312438.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐