自从我更新到Android Studio 2.2并开始使用新的UI Builder和
我有一个简单的布局,其中包含
ConstraintLayout
之后,出现了一个问题,我无法解决。我有一个简单的布局,其中包含
ImageView
和位于ImageView
右侧的TextView
。 TextView
中的文本会动态地从服务器更新(我不知道这个文本的确切长度)。 我想让TextView
利用ImageView
和屏幕右侧之间的所有可用空间。 以前,我使用RelativeLayout
并设置TextView
android:layout_width="wrap_content"
即可解决此问题。<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/imageView"
android:layout_width="116dp"
android:layout_height="178dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="16dp"
android:layout_marginTop="16dp"
tools:src="@drawable/pets"/>
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/imageView"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_toEndOf="@+id/imageView"
android:layout_toRightOf="@+id/imageView"
tools:text="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque molestie tincidunt mi a gravida. Aenean faucibus a sapien ut consequat. Praesent sed placerat quam."/>
</RelativeLayout>
但是当我使用ConstraintLayout时,没有文字换行,TextView会超出屏幕。
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/imageView"
android:layout_width="116dp"
android:layout_height="178dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="16dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/pets"/>
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginTop="16dp"
android:ellipsize="none"
android:text="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque molestie tincidunt mi a gravida. Aenean faucibus a sapien ut consequat. Praesent sed placerat quam."
app:layout_constraintLeft_toRightOf="@+id/imageView"
app:layout_constraintTop_toTopOf="parent"/>
</android.support.constraint.ConstraintLayout>