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这个属性就行了,问题迎刃而解。

LinearLayout-margin不起作用的处理的更多相关文章

  1. HTML中div嵌套div的margin不起作用

    下面介绍一下div嵌套div时margin不起作用的解决方案. 顺便科普下margin的定义和用法. div嵌套的HTML代码: <!DOCTYPE html> <html lang ...

  2. LinearLayout属性baselineAligned的作用及baseline

    相信大家对LinearLayout已经相当熟悉,但你们是否了解它的属性baselineAligned呢? Android官方文档是这么描述的:

  3. 【转】Android 布局学习之——LinearLayout属性baselineAligned的作用及baseline

    相信大家对LinearLayout已经相当熟悉,但你们是否了解它的属性baselineAligned呢? Android官方文档是这么描述的:

  4. Android 布局学习之——LinearLayout属性baselineAligned的作用及baseline

    相信大家对LinearLayout已经相当熟悉,但你们是否了解它的属性baselineAligned呢? Android官方文档是这么描述的:

  5. Android 布局学习之——LinearLayout属性baselineAligned的作用及baseline(转载)

    转自:http://www.cnblogs.com/JohnTsai/p/4074643.html 相信大家对LinearLayout已经相当熟悉,但你们是否了解它的属性baselineAligned ...

  6. margin负值的作用

    一.左右负margin改变自身宽度 当元素不存在width或者width:auto的时候,负margin会增加元素的宽度. html <div class="parent"& ...

  7. CSS margin详解

    以下的分享是本人最近几天学习了margin知识后,大有启发,感觉以前对margin的了解简直太浅薄.所以写成以下文章,一是供自己整理思路:二是把知识分享出来,避免各位对margin属性的误解.内容可能 ...

  8. 负margin的原理以及应用

    负margin在布局中往往起到意想不到的效果,比如在多栏等高布局中就是用该技巧. 虽说网络上关于负margin的实践有很多,但对margin负值为什么会出现这样的效果却没有多少讲解,本篇的目的就是阐述 ...

  9. css margin的相关属性,问题及应用

    by zhangxinxu from http://www.zhangxinxu.com本文地址:http://www.zhangxinxu.com/wordpress/?p=48 引言:margin ...

  10. clear:both后margin-top不起作用

    如: <div style="float:left;">float:left</div> <div style="clear:both;ma ...

随机推荐

  1. 基于express+redis高速实现实时在线用户数统计

    作者:zhanhailiang 日期:2014-11-09 本文将介绍怎样基于express+redis高速实现实时在线用户数统计. 1. 在github.com上创建项目uv-tj.将其同步到本地: ...

  2. 玲珑学院 1010 - Alarm

    1010 - Alarm Time Limit:1s Memory Limit:128MByte DESCRIPTION Given a number sequence [3,7,22,45,116, ...

  3. [Chromium文档转载,第001章] Mojo Migration Guide

        For Developers‎ > ‎Design Documents‎ > ‎Mojo‎ > ‎ Mojo Migration Guide 目录 1 Summary 2 H ...

  4. Python正则表达式初识(六)

    继续分享Python正则表达式基础,今天给大家分享的正则表达式特殊符号是“[]”.中括号十分实用,其有特殊含义,其代表的意思是中括号中的字符只要满足其中任意一个就可以.其用法一共有三种,分别对其进行具 ...

  5. scrollWidth到底是什么???

    贴上MDN对scrollwidth的定义: The Element.scrollWidth read-only property is a measurement of the width of an ...

  6. 学习参考《矩阵分析与应用(第二版)张贤达》PDF

    要想深入理解机器学习,或者对人工智能的某个领域有所研究,都必须掌握矩阵及其应用. 学习<矩阵分析与应用第2版>时,会发现总结了大量线性代数的知识,主要是给工科生用的.归纳了不少论文中的解法 ...

  7. CSUOJ 1525 Algebraic Teamwork

    Problem A Algebraic Teamwork The great pioneers of group theory and linear algebra want to cooperate ...

  8. H+后台主题UI框架---整理

    本篇文章是对H+这种框架进行整理,顺便了解一下标准的代码规范的写法. 一.表单: 1).下面是一个基本表单: 现在来看这个表单的结构: 1.整个表单的外框结构是一个div,至于padding和marg ...

  9. POJ 1991 DP

    题意: 思路: 考虑DP 先把事件按照地点顺序排个序 f[i][j][0]表示从i到j还没有去过 现在在i f[i][j][1]表示从i到j还没有去过 现在在j 那么方程就呼之欲出了 f[i][j][ ...

  10. Android Retrofit+RxJava 优雅的处理服务器返回异常、错误

    标签: 开始本博客之前,请先阅读: Retrofit请求数据对错误以及网络异常的处理 异常&错误 实际开发经常有这种情况,比如登录请求,接口返回的 信息包括请求返回的状态:失败还是成功,错误码 ...