由于我已更新到Android Studio 2.2并开始使用ConstraintLayout
与新的UI生成器有一个问题,我无法解决。ConstraintLayout和TextView的问题wrap_content
我有一个简单的布局,ImageView
和TextView
在ImageView
的右边。 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,没有textwrap和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>
是啊!有用!谢谢! – rbaloo
它不工作。我已经安装了alpha 9&ConstraintLayout 1.0.2,但它不工作。内容超出屏幕 – Amit