我使用下面的布局来实现约束布局右端的图像视图,以及图像左侧的文本:
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:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:id="@+id/parentPanel"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
android:id="@+id/image"
android:layout_width="64dp"
android:layout_height="64dp"
app:layout_constraintRight_toRightOf="parent"
android:background="#ff0000"/>
android:id="@+id/txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Lorem Ipsum is simply dummy text of the printing
and typesetting industry. Lorem Ipsum has been the industry's
standard dummy text ever since the 1500s, when an unknown printer took
a galley of type and scrambled it to make a type specimen book"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toLeftOf="@+id/image"
android:textColor="#000000"
android:textSize="20sp"/>
constraint.ConstraintLayout>
我附上了从上面的XML获得的UI的截图.当文本太长时,文本将被剪切在左侧.
build.gradle中使用的依赖项是:
编译’com.android.support.constraint:constraint-layout:1.0.1′