java使用百分比相对布局创建间距
我的问题是,我在屏幕上有四个按钮,我使用PercentageRelativeLayout将它们放在我想要的地方,一切都很好
它们甚至可以调整大小
然而,当它们调整大小时,按钮开始相互接触,当我在平板电脑上这样做时,它们不会相互接触,当我回到手机时,空间距离太远
有人知道我如何创建一个可以在所有设备上工作的间距吗
因为我认为PercentageRelativeLayouts是在不使用任何LinearLayout的情况下调整大小的完美解决方案,而且它的工作方式与我的想法不同
下面是我的代码
<安卓.support.percent.PercentRelativeLayout xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
xmlns:app="http://schemas.安卓.com/apk/res-auto"
安卓:layout_width="match_parent"
安卓:layout_height="match_parent"
安卓:background="#696969">
<ImageButton
app:layout_widthPercent="40%"
app:layout_heightPercent="40%"
app:layout_marginLeftPercent="9%"
app:layout_marginTopPercent="21%"
安卓:background="#00ff0000"
安卓:layout_width="fill_parent"
安卓:layout_height="fill_parent"
安卓:src="@drawable/opt1"
安卓:scaleType="fitCenter"
安卓:id="@+id/purpleButton"
安卓:layout_align="@+id/option1"
安卓:longClickable="false" />
<ImageButton
app:layout_widthPercent="40%"
app:layout_heightPercent="40%"
app:layout_marginLeftPercent="9%"
app:layout_marginTopPercent="58%"
安卓:background="#00ff0000"
安卓:layout_height="fill_parent"
安卓:src="@drawable/opt2"
安卓:scaleType="fitStart"
安卓:id="@+id/option2"
安卓:layout_width="fill_parent"
安卓:longClickable="false" />
<ImageButton
app:layout_widthPercent="40%"
app:layout_heightPercent="40%"
app:layout_marginLeftPercent="50%"
app:layout_marginTopPercent="58%"
安卓:background="#00ff0000"
安卓:layout_height="fill_parent"
安卓:src="@drawable/opt3"
安卓:scaleType="fitStart"
安卓:id="@+id/option3"
安卓:layout_width="fill_parent"
安卓:longClickable="false" />
<ImageButton
app:layout_widthPercent="40%"
app:layout_heightPercent="40%"
app:layout_marginLeftPercent="50%"
app:layout_marginTopPercent="21%"
安卓:background="#00ff0000"
安卓:layout_width="fill_parent"
安卓:layout_height="fill_parent"
安卓:src="@drawable/option4"
安卓:scaleType="fitCenter"
安卓:id="@+id/opt4"
安卓:longClickable="false" />
<TextView
安卓:layout_width="wrap_content"
安卓:layout_height="wrap_content"
安卓:textAppearance="?安卓:attr/textAppearanceLarge"
安卓:text="Pick an Answer"
安卓:id="@+id/pickLabel"
安卓:layout_alignParentTop="true"
安卓:layout_centerHorizontal="true"
安卓:layout_marginTop="28dp"
app:layout_widthPercent="100%"
app:layout_heightPercent="7%"
app:layout_marginTopPercent="15%"
安卓:textColor="#ffffff"
安卓:textAlignment="center"
安卓:textSize="30sp" />
<TextView
安卓:layout_width="wrap_content"
安卓:layout_height="wrap_content"
app:layout_widthPercent="100%"
app:layout_heightPercent="12%"
安卓:textAppearance="?安卓:attr/textAppearanceLarge"
安卓:text="00"
安卓:id="@+id/timeLabel"
安卓:textAlignment="gravity"
安卓:textSize="72sp"
安卓:gravity="center|center_vertical|center_horizontal" />
# 1 楼答案
您可以在外部布局上设置
android:weightSum="1"
,在内部布局上设置android:layout_weight="0.25"