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".)

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.

其中left/right是代表一种绝对的对齐,start/end表示基于阅读顺序的对齐。
那么说到阅读顺序又不得不提目前存在的主要阅读方式:
  从左向右(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

更多相关文章

  1. 箭头函数的基础使用
  2. NPM 和webpack 的基础使用
  3. Python list sort方法的具体使用
  4. 【阿里云镜像】使用阿里巴巴DNS镜像源——DNS配置教程
  5. Android中使用自定义Dialog时match_parent无效的问题
  6. 如何编写高效的android代码(1)
  7. 你不知道一些神奇Android(安卓)Api
  8. 关于ellipsize属性使用的一些细节
  9. 下拉选择菜单Spinner的使用

随机推荐

  1. 【Android动态布局】之【使用addView方法
  2. Android FragmentManage FragmentTransac
  3. Android监听手机网络变化
  4. Android中RecyclerView调用notifyDataSet
  5. Android Google Maps API key 申请
  6. android 点击listView没有反应
  7. Android AlertDialog有EditText无法弹出
  8. 使用Scala开发Android
  9. Android的Activity实时刷新
  10. Android_Build_System