【发布时间】:2019-03-29 08:35:49
【问题描述】:
我试图在我的布局文件的 Constraintlayout 中为两个 Textview 提供正确的位置。问题是文本视图需要使用应用程序进行扩展:autoSizeTextType="uniform"。为了使它们扩展,我还必须在layout_width 和layout_height 上匹配_parent。这使得两个文本视图重叠。我怎样才能达到预期的效果?
当前 XML 文件:
<?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"
android:background="@color/colorPrimary"
android:gravity="center"
android:orientation="vertical">
<TextView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="1"
android:textColor="#4689C8"
android:textStyle="bold"
app:autoSizeTextType="uniform"
app:layout_constrainedHeight="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.362" />
<TextView
android:id="@+id/message"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="ABC"
android:textColor="#4689C8"
android:textStyle="bold"
app:autoSizeTextType="uniform"
app:layout_constrainedHeight="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</android.support.constraint.ConstraintLayout>
实际结果:
两个文本视图都缩放,但重叠,并放置在约束布局的中心。
当前状态:
预期结果:
一个文本视图在中间居中。一个文本视图在底部对齐。两个文本视图都与约束布局一起缩放。 预期结果:(活动中有 3 种不同的自定义化合物)
【问题讨论】:
-
您需要为 textview 使用固定高度,而不是 match_parent 才能自动调整大小。
标签: android xml textview android-constraintlayout