gpt4 book ai didi

java - 为什么将设备语言更改为 RTL 语言时 fragment/Activity 布局看起来很糟糕?

转载 作者:行者123 更新时间:2023-12-01 17:45:45 27 4
gpt4 key购买 nike

我构建了一个应用程序(用于练习 Android),并使用 startend 来支持 LTR RTL 语言。我还在 list 文件中设置了 android:supportsRtl="true" 。当设备设置为LTR语言时,所有文本看起来都很棒,而且左侧对齐也很好。 但是,当将设备语言更改为RTL语言时,所有文本看起来都很糟糕并且没有向右对齐(也许某些TextView是对齐,有些则不然)。此外,Spinner View 似乎完全错误。我附上了两个屏幕截图(两种语言)。我请求你的帮助,因为我不明白我做错了什么。还附上了 3 个代码 fragment (一个用于所有布局,第二个用于 RecyclerView 内的项目,第三个用于 Spinner 的项目:

    <?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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"
android:background="@color/backgroundColor">

<Spinner
android:id="@+id/spinner"
android:layout_width="0dp"
android:layout_height="48dp"
android:layout_marginStart="3dp"
android:layout_marginTop="5dp"
android:layout_marginEnd="3dp"
android:background="@null"
android:dropDownWidth="120dp"
android:dropDownVerticalOffset="96dp"
android:gravity="center"
android:visibility="invisible"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />


<com.example.currencyconvertor.MultiButton
android:id="@+id/multiButton"
android:layout_width="300dp"
android:layout_height="50dp"
android:layout_marginTop="15dp"
app:activeButtonIndex="0"
app:backgroundSelector="@drawable/multi_button_background_selector"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/spinner"
app:numOfButtons="2"
app:reversedOrder="false"
android:visibility="gone"
app:textColorSelector="@drawable/multi_button_text_color" />


<TextView
android:id="@+id/textView1"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:layout_marginStart="3dp"
android:layout_marginTop="22dp"
android:textColor="@color/titleTextColor"
android:textSize="13sp"
app:layout_constraintEnd_toStartOf="@id/textView2"
app:layout_constraintHorizontal_chainStyle="spread_inside"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/multiButton"
tools:text="TextView1" />


<TextView
android:id="@+id/textView2"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:text="Symbol"
android:textColor="@color/titleTextColor"
android:textSize="13sp"
app:layout_constraintEnd_toStartOf="@id/textView3"
app:layout_constraintStart_toEndOf="@id/textView1"
app:layout_constraintTop_toTopOf="@id/textView1"
tools:text="TextView2" />

<TextView
android:id="@+id/textView3"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:textColor="@color/titleTextColor"
android:textSize="13sp"
app:layout_constraintEnd_toStartOf="@id/textView4"
app:layout_constraintStart_toEndOf="@id/textView2"
app:layout_constraintTop_toTopOf="@id/textView1"
app:layout_goneMarginEnd="3dp"
tools:text="TextView3" />

<TextView
android:id="@+id/textView4"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:layout_marginEnd="3dp"
android:textColor="@color/titleTextColor"
android:textSize="13sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/textView3"
app:layout_constraintTop_toTopOf="@id/textView1"
android:visibility="gone"
tools:text="TextView4" />


<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="3dp"
android:layout_marginTop="7dp"
android:layout_marginEnd="3dp"
android:visibility="visible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/textView1"
tools:listitem="@layout/relative_currency_rate_row" />

<ProgressBar
android:id="@+id/progressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxHeight="200dp"
android:maxWidth="200dp"
android:visibility="visible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/textView1" />
</androidx.constraintlayout.widget.ConstraintLayout>

RecyclerView 项目的代码:

  <?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"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginBottom="1dp"
android:background="@color/rowColor"

xmlns:app="http://schemas.android.com/apk/res-auto">


<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/container"
android:layout_width="80dp"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="@id/targetCountryTextView"
app:layout_constraintHorizontal_chainStyle="spread_inside"
tools:ignore="MissingConstraints">


<ImageView android:id="@+id/countryFlagImageView"
android:layout_width="32dp"
android:layout_height="32dp"
app:layout_constraintStart_toStartOf="@id/container"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:src="@drawable/ic_launcher_background"
android:paddingEnd="4dp" />

<TextView
android:id="@+id/currencyTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintStart_toEndOf="@id/countryFlagImageView"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginStart="2dp"
android:layout_marginTop="13dp"
android:layout_marginBottom="12dp"
android:textSize="13sp"
android:text="USA"
android:textColor="@color/currencyRowTextColor"/>
</androidx.constraintlayout.widget.ConstraintLayout>

<TextView
android:id="@+id/targetCountryTextView"
android:layout_width="80dp"
android:layout_height="wrap_content"
app:layout_constraintStart_toEndOf="@id/container"
app:layout_constraintEnd_toStartOf="@id/rateTextView"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginTop="13dp"
android:layout_marginBottom="12dp"
android:textSize="13sp"
android:text="Dollar"
android:textColor="@color/currencyRowTextColor" />


<TextView
android:id="@+id/rateTextView"
android:layout_width="80dp"
android:layout_height="wrap_content"
app:layout_constraintStart_toEndOf="@id/targetCountryTextView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginTop="13dp"
android:layout_marginBottom="12dp"
android:textSize="13sp"
android:text="0.417"
android:textColor="@color/currencyRowTextColor" />

</androidx.constraintlayout.widget.ConstraintLayout>

微调项目代码:

 <?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/rowColor">

<ImageView
android:id="@+id/flagImageView"
android:layout_width="48dp"
android:layout_height="48dp"
app:layout_constraintEnd_toStartOf="@+id/countryTextView"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:padding="4dp"
app:srcCompat="@drawable/default_glag"
android:textColor="@color/currencyRowTextColor"/>

<TextView
android:id="@+id/countryTextView"
android:layout_width="wrap_content"
android:layout_height="0dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@id/flagImageView"
android:layout_marginStart="30dp"
android:gravity="center"
android:textSize="17sp"
android:textColor="@color/currencyRowTextColor"/>

<TextView
android:id="@+id/currencyTextView"
android:layout_width="wrap_content"
android:layout_height="0dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@id/countryTextView"
android:layout_marginStart="5dp"
android:gravity="center"
android:text="countryCurrencyTextView"
android:textSize="17sp"
android:textColor="@color/currencyRowTextColor"/>

<ImageView
android:layout_width="48dp"
android:layout_height="48dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginEnd="4dp"
android:src="@mipmap/ic_arrow_drop_down"/>
</androidx.constraintlayout.widget.ConstraintLayout>[![enter image description here][1]][1]

LTR

RTL

最佳答案

在 list 文件上禁用 RTL 支持:

<application
...
android:supportsRtl="false">

希望对您有用;)

关于java - 为什么将设备语言更改为 RTL 语言时 fragment/Activity 布局看起来很糟糕?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60867825/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com