java约束布局在不同的设备上执行不同的操作
我正试图将我的相对布局转换为约束布局,以适合每台设备,但我遇到了一些问题。在Android Studio的编辑器上,它如下所示:
我用一个象素C做模拟器。现在,我在三星Galaxy标签上试用了该应用程序,结果如下:
为什么按钮不像第一张图片那样位于屏幕中央?这是xml的代码,您可以看到,我甚至锚定了元素以保持它们之间的距离:
<安卓.support.constraint.ConstraintLayout xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
xmlns:app="http://schemas.安卓.com/apk/res-auto"
xmlns:tools="http://schemas.安卓.com/tools"
安卓:id="@+id/relativeLayout"
安卓:layout_width="fill_parent"
安卓:layout_height="fill_parent"
安卓:background="@drawable/background_main"
安卓:scaleType="centerCrop"
tools:context=".MainActivity">
<TextView
安卓:id="@+id/textView2"
安卓:layout_width="708dp"
安卓:layout_height="231dp"
安卓:layout_marginTop="152dp"
安卓:layout_marginEnd="8dp"
安卓:layout_marginBottom="8dp"
安卓:fontFamily="@font/kotta_one"
安卓:text="Test del pensiero\n divergente"
安卓:textColor="#000000"
安卓:textSize="86dp"
安卓:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.57"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.195" />
<Button
安卓:id="@+id/button_1"
安卓:layout_width="180dp"
安卓:layout_height="60dp"
安卓:layout_marginStart="8dp"
安卓:layout_marginEnd="76dp"
安卓:layout_marginBottom="8dp"
安卓:background="@drawable/button_bg"
安卓:text="@string/invioA"
安卓:textAllCaps="false"
安卓:textColor="#FFFFFF"
安卓:textSize="18dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/button_2"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="@+id/textView2"
app:layout_constraintTop_toBottomOf="@+id/textView2"
app:layout_constraintVertical_bias="0.028" />
<Button
安卓:id="@+id/button_2"
安卓:layout_width="180dp"
安卓:layout_height="60dp"
安卓:layout_marginEnd="188dp"
安卓:layout_marginBottom="8dp"
安卓:background="@drawable/button_bg"
安卓:text="@string/invioB"
安卓:textAllCaps="false"
安卓:textColor="#FFFFFF"
安卓:textSize="18dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="@+id/textView2"
app:layout_constraintTop_toBottomOf="@+id/textView2"
app:layout_constraintVertical_bias="0.028" />
<Button
安卓:id="@+id/button_3"
安卓:layout_width="161dp"
安卓:layout_height="114dp"
安卓:layout_marginEnd="8dp"
安卓:background="@安卓:color/transparent"
安卓:fontFamily="@font/kotta_one"
安卓:text="Area\nDocenti"
安卓:textAllCaps="false"
安卓:textColor="#030000"
安卓:textSize="26dp"
app:layout_constraintEnd_toStartOf="@+id/textView2"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</安卓.support.constraint.ConstraintLayout>
# 1 楼答案