-1
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.hp.buttonconstraints.MainActivity">
<Button
android:id="@+id/answerBtnTwo"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginEnd="10dp"
android:layout_marginLeft="6dp"
android:layout_marginRight="10dp"
android:layout_marginStart="6dp"
android:background="@drawable/red_rectangle"
android:paddingBottom="5dp"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingTop="5dp"
android:text="Text"
android:textColor="@android:color/black"
android:textSize="12sp"
app:layout_constraintBottom_toBottomOf="@+id/answerBtnOne"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintLeft_toRightOf="@+id/answerBtnOne"
app:layout_constraintRight_toRightOf="@+id/questionBacksplash"
app:layout_constraintTop_toTopOf="@+id/answerBtnOne"
app:layout_constraintVertical_bias="0.0"
tools:ignore="HardcodedText"
tools:layout_constraintBottom_creator="1"
tools:layout_constraintLeft_creator="1"
tools:layout_constraintRight_creator="1"
tools:layout_constraintTop_creator="1" />
<Button
android:id="@+id/answerBtnOne"
android:layout_width="148dp"
android:layout_height="56dp"
android:layout_marginBottom="4dp"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:background="@drawable/red_rectangle"
android:paddingBottom="5dp"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingTop="5dp"
android:text="Text"
android:textColor="@android:color/black"
android:textSize="12sp"
app:layout_constraintBottom_toTopOf="@+id/answerBtnThree"
app:layout_constraintLeft_toLeftOf="@+id/questionBacksplash"
tools:ignore="HardcodedText"
tools:layout_constraintBottom_creator="1"
tools:layout_constraintLeft_creator="1" />
<Button
android:id="@+id/answerBtnThree"
android:layout_width="0dp"
android:layout_height="56dp"
android:layout_marginBottom="64dp"
android:background="@drawable/red_rectangle"
android:elevation="1dp"
android:paddingBottom="5dp"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingTop="5dp"
android:text="Text"
android:textColor="@android:color/black"
android:textSize="12sp"
app:layout_constraintBottom_toTopOf="@+id/answerBtnSeven"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintLeft_toLeftOf="@+id/answerBtnOne"
app:layout_constraintRight_toRightOf="@+id/answerBtnOne"
tools:ignore="HardcodedText"
tools:layout_constraintBottom_creator="1"
tools:layout_constraintLeft_creator="1"
tools:layout_constraintRight_creator="1"
tools:targetApi="lollipop" />
<Button
android:id="@+id/answerBtnFive"
android:layout_width="148dp"
android:layout_height="56dp"
android:layout_marginBottom="60dp"
android:layout_marginEnd="1dp"
android:layout_marginRight="1dp"
android:layout_marginTop="60dp"
android:background="@drawable/red_rectangle"
android:elevation="1dp"
android:paddingBottom="5dp"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingTop="5dp"
android:text="Text"
android:textColor="@android:color/black"
android:textSize="12sp"
app:layout_constraintBottom_toBottomOf="@+id/answerBtnSeven"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintRight_toRightOf="@+id/answerBtnThree"
app:layout_constraintTop_toTopOf="@+id/answerBtnThree"
app:layout_constraintVertical_bias="0.0"
tools:ignore="HardcodedText,UnusedAttribute"
tools:layout_constraintBottom_creator="1"
tools:layout_constraintRight_creator="1"
tools:layout_constraintTop_creator="1" />
<Button
android:id="@+id/answerBtnSeven"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="@drawable/red_rectangle"
android:elevation="1dp"
android:paddingBottom="5dp"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingTop="5dp"
android:text="Text"
android:textColor="@android:color/black"
android:textSize="12sp"
app:layout_constraintBottom_toBottomOf="@+id/answerBtnEight"
app:layout_constraintLeft_toLeftOf="@+id/answerBtnThree"
app:layout_constraintRight_toRightOf="@+id/answerBtnThree"
app:layout_constraintTop_toTopOf="@+id/answerBtnEight"
tools:ignore="HardcodedText,UnusedAttribute"
tools:layout_constraintBottom_creator="1"
tools:layout_constraintLeft_creator="1"
tools:layout_constraintRight_creator="1"
tools:layout_constraintTop_creator="1" />
<Button
android:id="@+id/answerBtnEight"
android:layout_width="0dp"
android:layout_height="56dp"
android:layout_marginBottom="29dp"
android:background="@drawable/red_rectangle"
android:paddingBottom="5dp"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingTop="5dp"
android:text="Text"
android:textColor="@android:color/black"
android:textSize="12sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="@+id/answerBtnSix"
app:layout_constraintRight_toRightOf="@+id/answerBtnSix"
tools:ignore="HardcodedText"
tools:layout_constraintBottom_creator="1"
tools:layout_constraintLeft_creator="1"
tools:layout_constraintRight_creator="1" />
<Button
android:id="@+id/answerBtnSix"
android:layout_width="0dp"
android:layout_height="56dp"
android:layout_marginBottom="4dp"
android:background="@drawable/red_rectangle"
android:paddingBottom="5dp"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingTop="5dp"
android:text="Text"
android:textColor="@android:color/black"
android:textSize="12sp"
app:layout_constraintBottom_toTopOf="@+id/answerBtnEight"
app:layout_constraintLeft_toLeftOf="@+id/answerBtnFour"
app:layout_constraintRight_toRightOf="@+id/answerBtnFour"
tools:ignore="HardcodedText"
tools:layout_constraintBottom_creator="1"
tools:layout_constraintLeft_creator="1"
tools:layout_constraintRight_creator="1" />
<Button
android:id="@+id/answerBtnFour"
android:layout_width="148dp"
android:layout_height="56dp"
android:layout_marginBottom="4dp"
android:layout_marginLeft="1dp"
android:layout_marginStart="1dp"
android:background="@drawable/red_rectangle"
android:paddingBottom="5dp"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingTop="5dp"
android:text="Text"
android:textColor="@android:color/black"
android:textSize="12sp"
app:layout_constraintBottom_toTopOf="@+id/answerBtnSix"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="@+id/answerBtnTwo"
tools:ignore="HardcodedText"
tools:layout_constraintBottom_creator="1"
tools:layout_constraintLeft_creator="1" />
<ImageButton
android:id="@+id/questionBacksplash"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginBottom="9dp"
android:layout_marginEnd="19dp"
android:layout_marginLeft="19dp"
android:layout_marginRight="19dp"
android:layout_marginStart="19dp"
android:background="@null"
app:layout_constraintBottom_toTopOf="@+id/answerBtnOne"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
tools:ignore="ContentDescription"
tools:layout_constraintBottom_creator="1"
tools:layout_constraintLeft_creator="1"
tools:layout_constraintRight_creator="1" />
...................................... ............Android按鈕限制和屏幕尺寸
我想在約束模式中添加一些按鈕到頁面,但我需要它們在不同的屏幕上調整大小。它出現按鈕1持有148dp的寬度,適用於Galaxy Nexus,但不適用於Nexus 4. Nexus 4需要158dp。但是,當我調整Nexus 4佈局中的按鈕大小時,它會在Galaxy佈局中縮小。現在有人可以告訴我怎麼解決這個
由於增加了尺寸 –
請如果答案是正確的,標記爲正確))謝謝 –