[英]Align ImageView to TextView baseline with ConstraintLayout
Is it possible to align the bottom of an ImageView
to the baseline of a TextView
using a ConstraintLayout
?是否可以使用ConstraintLayout
将ImageView
的底部与TextView
的基线对齐? It used to be easy with a RelativeLayout
but it seems to be gone from ConstraintLayout
.过去使用RelativeLayout
很容易,但它似乎从ConstraintLayout
消失了。 :( :(
yes, it can be achieved in constraintLayout using是的,它可以在约束布局中使用
android:baselineAlignBottom="true"
app:layout_constraintBaseline_toBaselineOf="@+id/textView"
please check below code:请检查以下代码:
<?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>
In the ImageView do: 在ImageView中:
app:layout_constraintBottom_toBottomOf="@id/textview"
That will align the bottom of the image to the bottom of the textview 这将使图像的底部与textview的底部对齐
If you want the image to be slightly above the text do: 如果您希望图像略高于文本,请执行以下操作:
app:layout_constraintBottom_toTopOf="@id/textview"
Or if you want it to be below it, do: 或者,如果您希望它低于它,请执行以下操作:
app:layout_constraintTop_toBottomOf="@id/textview"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.