我在ConstraintLayout中有三个TextView,边距使它们全部位于屏幕的中心。由于某种原因,TextViews中的文本被提前包装,即使第一行仍有空间。以下是预览中应该的布局:
以下是运行时的实际情况:
您可以在TextViews右侧看到文本可以放在第一行的额外空间。请记住,设备和预览都适用于Nexus 5X。
以下是此布局的XML:
<android.support.constraint.ConstraintLayout
android:id="@+id/bullet_holder"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="45dp"
android:layout_marginLeft="45dp"
android:layout_marginRight="45dp"
android:layout_marginStart="45dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/setup_intro_subheader"
app:layout_constraintVertical_bias="0.23000002">
<ImageView
android:id="@+id/setup_intro_bullet_first"
style="@style/TextAppearance.AppCompat.Headline"
android:layout_width="4dp"
android:layout_height="4dp"
android:baseline="7dp"
android:src="@drawable/circle"
app:layout_constraintBaseline_toBaselineOf="@+id/setup_intro_bullet_first_text"
app:layout_constraintLeft_toLeftOf="parent" />
<TextView
android:id="@+id/setup_intro_bullet_first_text"
style="@style/TextAppearance.AppCompat.Subhead"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="6dp"
android:layout_marginStart="6dp"
android:text="@string/setup_intro_benefit_notification"
android:textColor="@android:color/white"
app:layout_constraintLeft_toRightOf="@+id/setup_intro_bullet_first"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="@+id/setup_intro_bullet_second"
style="@style/TextAppearance.AppCompat.Headline"
android:layout_width="4dp"
android:layout_height="4dp"
android:baseline="7dp"
android:src="@drawable/circle"
app:layout_constraintBaseline_toBaselineOf="@+id/setup_intro_bullet_second_text"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="@+id/setup_intro_bullet_second_text" />
<TextView
android:id="@+id/setup_intro_bullet_second_text"
style="@style/TextAppearance.AppCompat.Subhead"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="6dp"
android:layout_marginStart="6dp"
android:layout_marginTop="20dp"
android:text="@string/setup_intro_benefit_backlog"
android:textColor="@android:color/white"
app:layout_constraintLeft_toRightOf="@+id/setup_intro_bullet_second"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/setup_intro_bullet_first_text" />
<ImageView
android:id="@+id/setup_intro_bullet_third"
style="@style/TextAppearance.AppCompat.Headline"
android:layout_width="4dp"
android:layout_height="4dp"
android:baseline="7dp"
android:src="@drawable/circle"
app:layout_constraintBaseline_toBaselineOf="@+id/setup_intro_bullet_third_text"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="@+id/setup_intro_bullet_third_text" />
<TextView
android:id="@+id/setup_intro_bullet_third_text"
style="@style/TextAppearance.AppCompat.Subhead"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="6dp"
android:layout_marginStart="6dp"
android:layout_marginTop="20dp"
android:text="@string/setup_intro_benefit_browser"
android:textColor="@android:color/white"
app:layout_constraintLeft_toRightOf="@+id/setup_intro_bullet_third"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/setup_intro_bullet_second_text" />
</android.support.constraint.ConstraintLayout>
答案 0 :(得分:5)
对于每个文本视图,请设置以下内容:
android:breakStrategy="simple"
这里更深层次的问题是,为什么设计师默认会显示与模拟器/设备不同的内容?