我想在Android中布局下面的rtl(从右到左)就像在父布局中使用layoutDirection =“rtl”(但它仅适用于4.2和更高版本)以及任何方式使其明确地从右向左.
这是主要的android项目布局的一部分,用于Android中的Preference Activity.
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackground"
android:gravity="center_vertical"
android:minHeight="?android:attr/listPreferredItemHeight"
android:paddingEnd="?android:attr/scrollbarSize" >
android:id="@+android:id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="6dip"
android:layout_marginEnd="6dip"
android:layout_marginStart="15dip"
android:layout_marginTop="6dip"
android:layout_weight="1" >
android:id="@+android:id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:fadingEdge="horizontal"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceLarge" />
android:id="@+android:id/summary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignStart="@android:id/title"
android:layout_below="@android:id/title"
android:maxLines="4"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="?android:attr/textColorSecondary" />
android:id="@+android:id/widget_frame"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:orientation="vertical" />
(抱歉我的英语不好!!)
解决方法:
不幸的是,Android 4.2(API级别17)或更高版本仅支持RTL布局支持功能.对于之前的版本,您可以为RTL布局添加布局文件夹.例如,在布局文件夹中放置LTR版本文件布局,在layout-ldrtl文件夹中放置RTL版本文件布局.
至于改变什么来制作RTL取决于你想在RTL中做多少.因为视图的某些部分将保留在同一侧(如导航栏),除非您自定义它.您将需要查看和更改应更改的内容以使其更酷的视图.例如,在LTR视图中,我们可以说:
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:orientation="horizontal"
android:paddingLeft="8dp"
android:paddingRight="4dp">
然后在RTL视图中你会像这样:
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:orientation="horizontal"
android:paddingLeft="4dp"
android:paddingRight="8dp">
你可以看到我们已经改变了android中的填充:paddingLeft =“4dp”和android:paddingRight =“8dp”但是我们保留了android:layout_gravity =“left”因为它应该像这种情况一样(也许在另一个视图将是android:layout_gravity =“right”).
作为现实生活中的示例,您可以比较Android Quran应用程序RTL audio_panel和LTR audio_panel的两个视图.
标签:android,android-layout,right-to-left
来源: https://codeday.me/bug/20190728/1560513.html