android - 在相对布局中平等对齐所有按钮
下面是一个简单的代码,我试图对齐所有按钮视图
- 如何确保所有按钮获得相等的空间,如图中我们可以看到的位置和照片按钮都不清楚 间隔开的
- 我也尝试过随机文本化它不起作用:(
任何想法
我尝试了什么::
<TableRow
android:id="@ id/tableRow5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="2sp" >
<RelativeLayout
android:id="@ id/BottomNavigationBarCopperChimneyDesc"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<Button
android:id="@ id/CopperChimneyDescriptionButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:text="Description"
android:textSize="14dp" />
<Button
android:id="@ id/CopperChimneyLocationButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@ id/CopperChimneyDescriptionButton"
android:text="Location"
android:textSize="14dp" />
<Button
android:id="@ id/CopperChimneyPhotosButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@ id/CopperChimneyFriendsButton"
android:text="Photos"
android:textSize="14dp" />
<Button
android:id="@ id/CopperChimneyFriendsButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="Friends"
android:textSize="15dp" />
</RelativeLayout>
</TableRow>
最佳答案:
2 个答案:
答案 0 :(得分:0)
如果您想要相同的尺寸,则需要使用LinearLayout。你可以把它放在RelativeLayout里面。你还需要给按钮相同的重量。就像这里:Equal buttons
答案 1 :(得分:0)
替代方法,有时可能有用。使用LinearLayout和权重的解决方案工作正常,但由于性能问题,我不喜欢可以轻松避免的额外布局膨胀。
<强> 1。在dimens.xml中定义按钮宽度。 Android手机的屏幕宽度为320或360dp:
值/ dimen.xml
<dimen name="button_width">80dp</dimen>
values-sw360dp / dimen.xml(这些资源将用于360dp宽度和更多的屏幕)
<dimen name="button_width">90dp</dimen>
当然,如果需要平板电脑支持,您应该定义额外的dimens.xml。
<强> 2。将此值用于按钮:
android:layout_width="@dimen/button_width"
本文经用户投稿或网站收集转载,如有侵权请联系本站。