我正在使用 ConstraintLayout 來創建活動視圖
有一個代碼片段:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom"
android:orientation="vertical"
tools:context=".presentation.screens.registration.RegistrationActivity">
<LinearLayout>...</LinearLayout>
<Button
android:id="@ id/login_next_btn"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:background="@drawable/button_green_disabled"
android:layout_width="match_parent"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="24dp"
android:text="@string/next"
android:textColor="@color/font_white"
android:textSize="16sp"
android:layout_height="48dp"
android:enabled="false"
android:onClick="onNextClick"/>
<ImageView
android:id="@ id/loader_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="@ id/login_next_btn"
android:src="@drawable/ic_loader"/>
</androidx.constraintlayout.widget.ConstraintLayout>
問題是:如何在 Button (@ id/login_next_btn) 的中心設定 ImageView (android:id="@ id/loader_image")?
uj5u.com熱心網友回復:
嘗試這個:
<ImageView
android:id="@ id/loader_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintLeft_toLeftOf="@id/login_next_btn"
app:layout_constraintRight_toRightOf="@id/login_next_btn"
app:layout_constraintBottom_toBottomOf="@id/login_next_btn"
app:layout_constraintTop_toTopOf="@id/login_next_btn"
android:src="@drawable/ic_loader"/>
uj5u.com熱心網友回復:
如果您必須將其設定在中心,只需更改影像的約束:
app:layout_constraintBottom_toBottomOf="@id/login_next_btn"
app:layout_constraintTop_toTopOf="@id/login_next_btn"
app:layout_constraintStart_toStartOf="@id/login_next_btn"
app:layout_constraintEnd_toEndOf="@id/login_next_btn"
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/427909.html
