【发布时间】:2017-01-10 05:58:24
【问题描述】:
我在 ConstraintLayout 中遇到了 TextView 的奇怪行为。
TextView 剪切文本。 在屏幕截图中,您会看到三个选项:
TextView 有 width="match_parent" - 边界正确,但文本被剪裁;
TextView 有 width="wrap_content" - 不正确的边界和文本再次被剪裁;
LinearLayout 内的TextView - 这是它应该是的示例。
ConstraintLayout,你怎么了?
这是我的 XML 布局。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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="#727272"
android:orientation="vertical"
android:padding="16dp">
<android.support.constraint.ConstraintLayout
android:id="@+id/block"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ffffff"
android:padding="16dp">
<ImageView
android:id="@+id/img"
android:layout_width="60dp"
android:layout_height="60dp"
android:background="#000000"
app:layout_constraintLeft_toLeftOf="@+id/block"
app:layout_constraintTop_toTopOf="@+id/block" />
<TextView
android:id="@+id/text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:background="#cccccc"
android:padding="6dp"
android:text="Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat."
app:layout_constraintLeft_toRightOf="@+id/img"
app:layout_constraintRight_toRightOf="@+id/block"
app:layout_constraintTop_toTopOf="@+id/img" />
</android.support.constraint.ConstraintLayout>
<android.support.constraint.ConstraintLayout
android:id="@+id/block2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ffffff"
android:padding="16dp">
<ImageView
android:id="@+id/img2"
android:layout_width="60dp"
android:layout_height="60dp"
android:background="#000000"
app:layout_constraintLeft_toLeftOf="@+id/block2"
app:layout_constraintTop_toTopOf="@+id/block2" />
<TextView
android:id="@+id/text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:background="#cccccc"
android:padding="6dp"
android:text="Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat."
app:layout_constraintLeft_toRightOf="@+id/img2"
app:layout_constraintRight_toRightOf="@+id/block2"
app:layout_constraintTop_toTopOf="@+id/img2" />
</android.support.constraint.ConstraintLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ffffff"
android:orientation="horizontal"
android:padding="16dp">
<ImageView
android:layout_width="60dp"
android:layout_height="60dp"
android:background="#000000" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:background="#cccccc"
android:padding="6dp"
android:text="Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat." />
</LinearLayout>
【问题讨论】:
-
ConstraintLayout版本是什么? -
@Ironman 'com.android.support.constraint:constraint-layout:1.0.0-alpha4'
标签: android android-layout textview android-constraintlayout