我在 RelativeLayout 中有一個文本視圖。它在 LTR 布局中運行良好。但是當我將其更改為 RTL 時,RelativeLayout 中的視圖會移出可見螢屏。我在布局檢查器中檢查它,我可以看到它超出了螢屏可見區域。視圖可見,但不在螢屏中。
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:fillViewport="true"
android:scrollbars="none">
<LinearLayout
android:id="@ id/empty"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:gravity="center"
android:orientation="vertical">
<androidx.appcompat.widget.AppCompatImageView
android:id="@ id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/ic_empty"
android:layout_gravity="center" />
<TextView
android:id="@ id/empty_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="16dp"
android:paddingTop="12dp"
android:paddingRight="16dp"
android:textAlignment="center"
android:textColor="@color/data_color"
android:textSize="@dimen/text_medium"
android:gravity="center_horizontal" />
<RelativeLayout
android:id="@ id/refresh"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:clickable="true"
android:focusable="true"
android:focusableInTouchMode="true"
android:minHeight="40dp">
<TextView
android:id="@ id/refresh_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:gravity="center"
android:text="@string/refresh" />
<ProgressBar
android:id="@ id/progress"
android:layout_width="@dimen/progressbar_width"
android:layout_height="@dimen/progressbar_height"
android:layout_centerInParent="true"
android:indeterminate="true"
android:visibility="gone" />
</RelativeLayout>
</LinearLayout>
</ScrollView>
refresh_text 是移出可見區域的 TextView。
uj5u.com熱心網友回復:
問題是相對布局使用 ConstraintLayout 試試這個代碼
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:fillViewport="true"
android:scrollbars="none">
<LinearLayout
android:id="@ id/empty"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:gravity="center"
android:orientation="vertical">
<androidx.appcompat.widget.AppCompatImageView
android:id="@ id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/ic_empty"
android:layout_gravity="center" />
<TextView
android:id="@ id/empty_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="16dp"
android:paddingTop="12dp"
android:paddingRight="16dp"
android:textAlignment="center"
android:textColor="@color/data_color"
android:textSize="@dimen/text_medium"
android:gravity="center_horizontal" />
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@ id/refresh"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:clickable="true"
android:focusable="true"
android:focusableInTouchMode="true"
android:minHeight="40dp">
<TextView
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:id="@ id/refresh_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/refresh" />
<ProgressBar
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:id="@ id/progress"
android:layout_width="@dimen/progressbar_width"
android:layout_height="@dimen/progressbar_height"
android:indeterminate="true"
android:visibility="gone" />
</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/504668.html
