![](/img/trans.png)
[英]Align ImageView with TextView in a ConstraintLayout
[英]Align ImageView to TextView baseline with ConstraintLayout
是否可以使用ConstraintLayout
將ImageView
的底部與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.