私の問題は、画面上に4つのボタンがあり、PercentageRelativeLayoutを使用してそれらを配置し、すべてがうまくいきました。
サイズを変更することさえできます!
しかし、彼らがサイズを変更すると、ボタンはお互いに触れ始めます。そして、タブレットでお互いに触れないようにすると、電話に戻ったときにスペースが離れすぎてしまいます。パーセンテージでの間隔の作成相対レイアウト
すべてのデバイスで動作するスペースをどのように作成することができますか?
PercentageRelativeLayoutsは、LinearLayoutを使用せずにリサイズするのに最適なソリューションだと思っていたので、思ったように動作していません。以下は
あなたが外レイアウトにandroid:weightSum="1"
を設定し、内部のレイアウトのandroid:layout_weight="0.25"
でき
<android.support.percent.PercentRelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#696969">
<ImageButton
app:layout_widthPercent="40%"
app:layout_heightPercent="40%"
app:layout_marginLeftPercent="9%"
app:layout_marginTopPercent="21%"
android:background="#00ff0000"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/opt1"
android:scaleType="fitCenter"
android:id="@+id/purpleButton"
android:layout_align="@+id/option1"
android:longClickable="false" />
<ImageButton
app:layout_widthPercent="40%"
app:layout_heightPercent="40%"
app:layout_marginLeftPercent="9%"
app:layout_marginTopPercent="58%"
android:background="#00ff0000"
android:layout_height="fill_parent"
android:src="@drawable/opt2"
android:scaleType="fitStart"
android:id="@+id/option2"
android:layout_width="fill_parent"
android:longClickable="false" />
<ImageButton
app:layout_widthPercent="40%"
app:layout_heightPercent="40%"
app:layout_marginLeftPercent="50%"
app:layout_marginTopPercent="58%"
android:background="#00ff0000"
android:layout_height="fill_parent"
android:src="@drawable/opt3"
android:scaleType="fitStart"
android:id="@+id/option3"
android:layout_width="fill_parent"
android:longClickable="false" />
<ImageButton
app:layout_widthPercent="40%"
app:layout_heightPercent="40%"
app:layout_marginLeftPercent="50%"
app:layout_marginTopPercent="21%"
android:background="#00ff0000"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/option4"
android:scaleType="fitCenter"
android:id="@+id/opt4"
android:longClickable="false" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Pick an Answer"
android:id="@+id/pickLabel"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="28dp"
app:layout_widthPercent="100%"
app:layout_heightPercent="7%"
app:layout_marginTopPercent="15%"
android:textColor="#ffffff"
android:textAlignment="center"
android:textSize="30sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_widthPercent="100%"
app:layout_heightPercent="12%"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="00"
android:id="@+id/timeLabel"
android:textAlignment="gravity"
android:textSize="72sp"
android:gravity="center|center_vertical|center_horizontal" />
現在のレイアウトを投稿してください。 – FlyingPumba
@FlyingPumbaレイアウトを追加しました –
@Rotwang dpsを使用するとビューがサイズ変更されることはなく、画面サイズに関係なく常に正確に同じサイズのままです –