1、如果LinearLayout中使用android:layout_marginRight不起作用,通过测试原来在android2.x中,如果一个控件中有android:layout_gravity属性,就会出现android:layout_marginRight没有应有的效果,而是把左边距加到右边距上去,直接去掉android:layout_gravity这个属性就能解决

2、如果是在RelativeLayout中不起作用,请在这个代码前加了一条android:layout_alignParentRight="true",就行(自己验证成功)

3、如果是ScrollView中的LinearLayout 中设置margin 类的属性无效,解决方法 LinearLayout中加android:layout_gravity="top" 属性就ok,

4、如果是LineaerLayout放到scrollview或者RelativeLayou里面中layout_margin失效不起作用,解决方法在属性里面加入android:layout_gravity="top",大家注意跟1是不一样的,1是LinearLayout里面的控件,而这里是指LinearLayout在其他控件中的情况,请分清对待。

5.我在一个relativelayout中放置了一个relativelayout,结果这个relativelayout中的layout_marginTop一直不起作用,后来发现是因为我的最外层relativelayout增加了另一个android:gravity="center",导致了问题

上面不知道是是个bug还是什么其他原因。

以上内容转载自:http://blog.csdn.net/lovexieyuan520/article/details/10499811

----我的经验:

我希望在一个actionmode中添加一个布局,如下

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/navigation_bar"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:orientation="horizontal">
     <RelativeLayout
  android:layout_marginTop="26dp"
  android:layout_width="match_parent"
  android:layout_height="match_parent">
<Button          android:id="@+id/cancel"
  android:layout_width="wrap_content"
   android:layout_height="wrap_content"
  android:layout_marginLeft="10dp"
  android:layout_centerVertical="true"
  android:src="@drawable/fm_return_selector" />
 <TextView           android:id="@+id/select"
   android:layout_height="wrap_content"
   android:layout_width="wrap_content" android:layout_toRightOf="@+id/cancel"   android:layout_alignParentRight="true"
   android:textSize="13sp"
   android:textColor="#ffffff" />
<Button       android:id="@+id/detail"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
   android:layout_centerVertical="true"
  android:layout_marginRight="10dp"
  android:layout_alignParentRight="true"
  android:src="@drawable/action_mode_detail" /> </RelativeLayout>     </LinearLayout>

结果发现,text永远不会居中,后来终于发现了问题,原来TORIGHTOF的意思是,你的控件左边跟另一个控件的右边对齐,如果你不添加layout_marginLeft,那么两个之间的距离是为零的,也就是所谓的严格对齐。而且,他的优先级似乎比android:layout_alignParentRight="true"更高,这就是它不发生作用的原因,只要去掉TORIGHTOF这个属性就行了,问题迎刃而解。

最新文章

  1. C#指定时间和当前时间的相差的月份、天数
  2. (转)DataGridView多维表头及其扩展功能
  3. Round robin
  4. Java 7 中 NIO.2 的使用——第二节 元数据文件的属性
  5. 如何把apache和nginx 加入到系统服务,用service 命令来控制启动、停止
  6. mysql中使用正则表达式时的注意事项
  7. 大批量烧写openwrt系统
  8. document.compatMode属性介绍
  9. vue2.0使用slot插槽分发内容
  10. Qt中QComboBox中自定义界面使用stylesheet实现下拉按钮独立效果
  11. 腾讯北京SNG一面
  12. linux下的系统垃圾清理
  13. 阿里巴巴excel工具easyexcel 助你快速简单避免OOM
  14. c语言实现:扫雷
  15. JS中获取CSS样式的方法
  16. maven依赖有一个步长原则 如果a 对 b和c都有依赖 如果b的步长近则使用b的
  17. Heaven of Imaginary(PKUSC2018)
  18. Coding 小技巧
  19. js 图片区域可点击,适配移动端,图片大小随意改变
  20. gunicorn工作原理

热门文章

  1. Unity 编辑器学习(四)之 静态游戏物体
  2. struts2.x + Tiles2.x读取多个xml 配置文件
  3. hdu-1342 Lotto
  4. UVa 11085 - Back to the 8-Queens
  5. 用户向导左右滑动页面实现之ImageSwitcher
  6. 7-07. PAT排名汇总(25) (结构体 ZJU_PAT)
  7. POJ 3275 两种做法
  8. codeforces 357C Knight Tournament(set)
  9. rowcount和@@rowcount的区别
  10. AIX 系统补丁升级步骤