Kum*_*mar 6 android android-layout android-constraintlayout
我希望我的textview和imageview像上面提到的图像.
1.我想使用约束布局在单行中水平设置Textview和Imageview.
2.Textview不会到达Imageview的中间(中间).(左右位置)
3.Also布局比重,没有努力使TextView的中心,由于Cosntraint布局
帮助我实现这一目标.
提前致谢.
<android.support.v7.widget.CardView
android:id="@+id/cv2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
app:cardCornerRadius="4dp"
app:layout_constraintTop_toBottomOf="@+id/cv1">
<android.support.constraint.ConstraintLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/title1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:text="Hero"
android:textColor="@color/colorPrimary"
android:textSize="16dp"
android:textStyle="bold"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="@+id/display_pic"
/>
<ImageView
android:id="@+id/display_pic"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_alignParentEnd="true"
android:layout_margin="16dp"
android:adjustViewBounds="false"
android:scaleType="centerCrop"
app:layout_constraintLeft_toLeftOf="@+id/title1"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@android:color/holo_red_light" />
</android.support.constraint.ConstraintLayout>
</android.support.v7.widget.CardView>
Run Code Online (Sandbox Code Playgroud)
Jua*_*ler 13
如果您希望ImageView在父项的右侧删除此属性:
app:layout_constraintLeft_toLeftOf="@+id/title1"
Run Code Online (Sandbox Code Playgroud)
如果要垂直对齐,请TextView添加以下属性:
app:layout_constraintTop_toTopOf="@id/display_pic"
app:layout_constraintBottom_toBottomOf="@id/display_pic"
Run Code Online (Sandbox Code Playgroud)
带有更改的xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
android:id="@+id/cv2"
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="wrap_content"
android:layout_gravity="center"
app:cardCornerRadius="4dp"
app:layout_constraintTop_toBottomOf="@+id/cv1">
<android.support.constraint.ConstraintLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/title1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:text="Hero"
android:textColor="@color/colorPrimary"
android:textSize="16dp"
android:textStyle="bold"
app:layout_constraintTop_toTopOf="@id/display_pic"
app:layout_constraintBottom_toBottomOf="@id/display_pic"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="@+id/display_pic"/>
<ImageView
android:id="@+id/display_pic"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_alignParentEnd="true"
android:adjustViewBounds="false"
android:scaleType="centerCrop"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@android:color/holo_red_light"/>
</android.support.constraint.ConstraintLayout>
</android.support.v7.widget.CardView>
Run Code Online (Sandbox Code Playgroud)
结果:
| 归档时间: |
|
| 查看次数: |
11913 次 |
| 最近记录: |