android - layout中setGravity=right和setLayoutDirection=rtl有什么区别

标签 android android-layout

当我想将布局方向更改为右侧时,如果我分配 android:gravity="right" 我将给出与分配 android:layoutDirection="rtl 时相同的结果".

我想知道这两者的区别

最佳答案

rtl表示 "right to left" ,你会使用 android:layoutDirection="rtl"如果您希望 View 组专门针对从右到左的语言(始终)显示内容,例如阿拉伯语。这就是为什么它使您的 View 向右对齐的原因。也就是说,我建议您避免使用 layoutDirection。因为它会覆盖设备的任何区域设置。

android:gravity="right"将 View 右对齐。我还建议您不要使用它(或 gravity="left" ),因为它不会针对 rtl 进行调整。语言,所以如果您发布应用程序的阿拉伯语版本,则布局对于您的阿拉伯语用户来说会很奇怪。

相反,您应该使用 android:gravity="end"因为这将使您的 View 在 ltr 中对齐语言(英语)并留在 rtl语言(阿拉伯语)。你需要有一个 minSDK>17使用结束和开始对齐,但我假设你是因为你还需要 17 的最小 sdk 才能使用 layoutDirection .

关于android - layout中setGravity=right和setLayoutDirection=rtl有什么区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38146700/

相关文章:

android - 如果数据库中的 "Image name"与目录中的 "Image Name"匹配,则在 gridview 中显示图像

php - Android 中与服务器数据库的连接

Android 从所有 View 中移除焦点

android-layout - RecyclerView SCROLL_STATE_IDLE 被延迟调用

Android 用 xml 中的另一个线性布局替换线性布局

android - 如何使用工具 :context to associtate Fragment files?

Android导航组件: dynamically adding fragment to graph

android - 如何以编程方式关闭网络浏览器?

android - 我应该使用哪些 RelativeLayout 属性?

android - 资源 $NotFoundException : Resource is not a ColorStateList (color or path): } in android