【Android】AS环境下,在布局中使用android:gravity="left/right"提示使用start/end
2017-02-20 16:11
1611 查看
1.问题产生
在AndroidStudio中,在布局文件中使用android:gravity属性设置属性值为left或right时,会有对应的警告提示,提示内容如下:
Use "start" instead of "left" to ensure correct behavior in right-to-left locales less... (Ctrl+F1) Using Gravity#LEFT and Gravity#RIGHT can lead to problems when a layout is rendered in locales where text flows from right to left. Use Gravity#START and Gravity#END instead. Similarly, in XML gravity and layout_gravity attributes, use start rather than left. For XML attributes such as paddingLeft and layout_marginLeft, use paddingStart and layout_marginStart. NOTE: If your minSdkVersion is less than 17, you should add both the older left/right attributes as well as the new start/right attributes. On older platforms, where RTL is not supported and the start/right attributes are unknown and therefore ignored, you need the older left/right attributes. There is a separate lint check which catches that type of error. (Note: For Gravity#LEFT and Gravity#START, you can use these constants even when targeting older platforms, because the start bitmask is a superset of the left bitmask. Therefore, you can use gravity="start" rather than gravity="left|start".)1
2
3
4
5
6
7
8
9
10
2.解决方法
从上面的警告内容中我们可以得知,当我们的minSdkVersion>=17时,使用start/end来代替left/right;当
minSdkVersion<17时,旧的平台不支持RTL,start/end属性是未知的,会被忽略,所以要同时使用start/end和left/right。
3.start/end与left/right有什么区别?
属性 | 说明 |
---|---|
left | Push object to the left of its container, not changing its size. |
right | Push object to the right of its container, not changing its size. |
start | Push object to the beginning of its container, not changing its size. |
end | Push object to the end of its container, not changing its size. |
那么说到阅读顺序又不得不提目前存在的主要阅读方式:
从左向右(LTR)和从右向左(RTL);当使用left/right的时候,无论是LTR还是RTL,总是左/右对齐的;而使用start/end,在LTR中是左/右对齐,而在RTL中则是右/左对齐。
注:
left/right属于绝对对齐,而start/end会根据不同国家习惯改变。如阅读顺序是从左到右(LTR)的国家,start在左边,在阅读顺序是从右到左(RTL)的国家,start在右边。
此小节内容参考自http://blog.csdn.net/tiewen/article/details/39925239
相关文章推荐
- 【Android】AS环境下,在布局中使用android:gravity="left/right"提示使用start/end
- 安卓:布局中使用android:gravity="left/right"提示使用start/end
- android布局文件中start,end,left,right的区别
- 抽屉的布局 android:layout_gravity="start"
- 一个线性布局中,为什么 android:layout_gravity="right"不能控制按钮在屏幕右侧?
- Consider adding android:paddingStart="1dip" to better support right-to-left layouts ......
- android让图片右边对齐的方法layout_gravity="right"
- Android动态布局,并动态为TextView控件设置drawableLeft、drawableRight等属性添加图标
- android xml布局文件中使用RelativeLayout,明明有这个id,却提示找不到---->解决办法
- Android布局中 android:layout_gravity="bottom";为何不起作用?
- TabHost和android:layout_height="0.0dip"以及android:layout_weight配合在布局中的使用
- [Android]Android布局文件中的android:id="@*"属性使用方法汇总以及介绍
- Android布局中layout_gravity与gravity的使用总结
- android xml布局文件中使用RelativeLayout,明明有这个id,却提示找不到---->解决办法
- TabHost和android:layout_height="0.0dip"以及android:layout_weight配合在布局中的使用
- 读入N, S两个自然数(0<=S,N<=9),打印相应的数字三角形(其中,S表示确定三角形的第一个数,N表示三角形的行数)。(提示:左右对齐可使用cout<<left、cout<<right)
- TabHost和android:layout_height="0.0dip"以及android:layout_weight配合在布局中的使用
- RelativieLayout布局中的android:gravity="center"属性
- Android动态布局,并动态为TextView控件设置drawableLeft、drawableRight等属性添加图标
- android TextView多行文本(超过3行)使用ellipsize="end"属性无效问题的解决方法