[英]android layout - position ImageButtons in equal quadrants of the screen and size them to proportion
[英]Create Layout/Screen with four ImageButtons (all of the same size)
我在创建仅包含四个ImageButton的Android布局时遇到了一个大问题。
它看起来应该像这样:
目前,我用两个LinearLayout创建了一个TableLayout(水平:每个包含两个按钮。)但是我通过设置确切的值来做到这一点:
<ImageButton
android:layout_width="178dp"
android:layout_height="260dp"
android:src="@drawable/personal_coach"
android:id="@+id/button_personal_coach"
android:layout_weight="0.25"
android:scaleType="fitXY"
android:background="?android:selectableItemBackground"
android:layout_marginRight="4dp"
/>
有一个更好的方法吗? (对于其他屏幕尺寸,更动态地设置宽度和高度为一个值)
尝试类似:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="2">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:weightSum="2"
android:orientation="horizontal">
<ImageButton
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"/>
<ImageButton
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:weightSum="2"
android:orientation="horizontal">
<ImageButton
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"/>
<ImageButton
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"/>
</LinearLayout>
</LinearLayout>
说明
在这里,我们使用weight属性,该属性根据重量将屏幕划分为百分比。 例如,在两个孩子中都放入1,将使他们占据屏幕的50%。 这就是我们首先在垂直方向上对每个按钮进行水平操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.