Android——layout_marginStart和layout_marginEnd的详细讲解
8.4.6 从右到左布局(RTL Layout)
从Android 4.2开始,Android SDK支持一种从右到左(RTL,Right-to-Left)UI布局的方式,尽管这种布局方式经常被使用在诸如阿拉伯语、希伯来语等环境中,中国用户很少使用。不过在某些特殊用途中还是很方便的。
所谓RTL,就是指按平常习惯在左的视图都会在右侧,在右侧的视图都会在左侧。例如,在线性布局中第1个子视图默认都是在左上角的,如果采用RTL布局,默认就在右上角了。
RTL布局默认是关闭的,如果想使用RTL布局,首先要在AndroidManifest.xml文件中将标签的android:supportsRtl属性值设为"true",然后需要将相应视图标签的android:layoutDirection属性值设为"rtl"。
如果要使用RTL布局,还应该注意一个重要的问题。假设一个水平线性布局中有两个
android:layout_marginStart:如果在LTR布局模式下,该属性等同于android:layout_marginLeft。如果在RTL布局模式下,该属性等同于android:layout_marginRight。
android:layout_marginEnd:如果在LTR布局模式下,该属性等同于android:layout_marginRight。如果在RTL布局模式下,该属性等同于android:layout_marginLeft。
首先来看下面的布局。
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:background="#000"
- android:orientation="horizontal" >
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:background="#F00"
- android:text="TextView1"
- android:textSize="30sp" />
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginStart="100dp"
- android:background="#F00"
- android:text="TextView2"
- android:textSize="30sp" />
- LinearLayout>
该布局是默认的LTR布局,所以两个TextView控件都是从左到右排列的,如图8-16所示。
现在将
更多相关文章
- 超级简单的android通过view自带的方法进行裁剪视图,实现圆形,矩形
- Android(安卓)用户界面---样式和主题(Styles and Themes)(一)
- Android(安卓)listview的适配器以及各种监听、效率的提升
- [置顶] android listview 连续调用 getview问题分析及解决。
- Android沉浸式状态栏(透明状态栏)最佳实现
- Activity的构成
- 利用Android属性动画实现Banner的原理与实践
- Android(安卓)RecyclerView 的 网格布局 ItemDecoration
- Android学习系列(5)--App布局初探之简单模型