Rak*_*hna 5 android android-layout android-constraintlayout
我使用以下布局来实现在约束布局的右端带有图像的视图,在图像的左侧带有文本:
<LinearLayout
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.support.constraint.ConstraintLayout
android:id="@+id/parentPanel"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/image"
android:layout_width="64dp"
android:layout_height="64dp"
app:layout_constraintRight_toRightOf="parent"
android:background="#ff0000"/>
<TextView
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"/>
</android.support.
constraint.ConstraintLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
我已附上了从XML上面获得的UI的屏幕截图。文本过长时,文本将从左侧截断。
在build.gradle中使用的依赖项是:
编译'com.android.support.constraint:constraint-layout:1.0.1'
你必须更改LinearLayout为ConstraintLayout. 您的布局应如下所示。
<?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:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.constraint.ConstraintLayout
android:id="@+id/parentPanel"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent" >
<ImageView
android:id="@+id/image"
android:layout_width="64dp"
android:layout_height="64dp"
android:background="#ff0000"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/txt"
android:layout_width="0dp"
android:layout_height="120dp"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
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_constraintLeft_toLeftOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:textColor="#000000"
android:textSize="20sp"
app:layout_constraintVertical_bias="0.0"
app:layout_constraintRight_toLeftOf="@+id/image"
android:layout_marginLeft="0dp"
android:layout_marginRight="8dp" />
</android.support.constraint.ConstraintLayout>
</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
645 次 |
| 最近记录: |