繁体   English   中英

使用 ConstraintLayout 将 ImageView 与 TextView 基线对齐

[英]Align ImageView to TextView baseline with ConstraintLayout

是否可以使用ConstraintLayoutImageView的底部与TextView的基线对齐? 过去使用RelativeLayout很容易,但它似乎从ConstraintLayout消失了。 :(

是的,它可以在约束布局中使用

android:baselineAlignBottom="true"
app:layout_constraintBaseline_toBaselineOf="@+id/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"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView
        android:id="@+id/imageView8"
        android:layout_width="wrap_content"
        android:layout_height="52dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:baselineAlignBottom="true"
        app:layout_constraintBaseline_toBaselineOf="@+id/textView33"

        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.815"
        app:layout_constraintStart_toStartOf="parent"
        app:srcCompat="@drawable/home_96" />

    <TextView
        android:id="@+id/textView33"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="16dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:text="TextView"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.59"
        app:layout_constraintStart_toStartOf="parent" />
</android.support.constraint.ConstraintLayout>

在ImageView中:

app:layout_constraintBottom_toBottomOf="@id/textview"

这将使图像的底部与textview的底部对齐

如果您希望图像略高于文本,请执行以下操作:

app:layout_constraintBottom_toTopOf="@id/textview"

或者,如果您希望它低于它,请执行以下操作:

app:layout_constraintTop_toBottomOf="@id/textview"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM