1、使用 Start娇昙、End代替Left惫搏、Right
如:
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:paddingLeft="8dp"
android:paddingRight="8dp"
替換為一下:
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:paddingStart="8dp"
android:paddingEnd="8dp"
2、TextView增加屬性android:textDirection="locale"
如:
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="小明"
android:textDirection="locale"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
3掠拳、ImageView圖片資源使用android:autoMirrored="true"
修飾
如:
\main\res\drawable\bitmap_icon.xml
<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:autoMirrored="true"
android:src="@drawable/icon">
</bitmap>
ImageView引用被bitmap修飾過的圖片資源
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/bitmap_icon" />
4癞揉、漸變背景適配使用drawable-ldrtl
資源
LTR : ...\main\res\drawable\bg_gradient.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:autoMirrored="true"
android:shape="rectangle">
<gradient
android:angle="0"
android:endColor="#00CD00"
android:centerColor="#FFFFFF"
android:startColor="#CD0000" />
<corners android:radius="@dimen/dp12" />
</shape>
RTL: ...\main\res\drawable-ldrtl\bg_gradient.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:autoMirrored="true"
android:shape="rectangle">
<gradient
android:angle="0"
android:endColor="#CD0000"
android:centerColor="#FFFFFF"
android:startColor="#00CD00" />
<corners android:radius="@dimen/dp12" />
</shape>