LinearLayout-margin不起作用的处理
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不起作用的处理的更多相关文章
- HTML中div嵌套div的margin不起作用
下面介绍一下div嵌套div时margin不起作用的解决方案. 顺便科普下margin的定义和用法. div嵌套的HTML代码: <!DOCTYPE html> <html lang ...
- LinearLayout属性baselineAligned的作用及baseline
相信大家对LinearLayout已经相当熟悉,但你们是否了解它的属性baselineAligned呢? Android官方文档是这么描述的:
- 【转】Android 布局学习之——LinearLayout属性baselineAligned的作用及baseline
相信大家对LinearLayout已经相当熟悉,但你们是否了解它的属性baselineAligned呢? Android官方文档是这么描述的:
- Android 布局学习之——LinearLayout属性baselineAligned的作用及baseline
相信大家对LinearLayout已经相当熟悉,但你们是否了解它的属性baselineAligned呢? Android官方文档是这么描述的:
- Android 布局学习之——LinearLayout属性baselineAligned的作用及baseline(转载)
转自:http://www.cnblogs.com/JohnTsai/p/4074643.html 相信大家对LinearLayout已经相当熟悉,但你们是否了解它的属性baselineAligned ...
- margin负值的作用
一.左右负margin改变自身宽度 当元素不存在width或者width:auto的时候,负margin会增加元素的宽度. html <div class="parent"& ...
- CSS margin详解
以下的分享是本人最近几天学习了margin知识后,大有启发,感觉以前对margin的了解简直太浅薄.所以写成以下文章,一是供自己整理思路:二是把知识分享出来,避免各位对margin属性的误解.内容可能 ...
- 负margin的原理以及应用
负margin在布局中往往起到意想不到的效果,比如在多栏等高布局中就是用该技巧. 虽说网络上关于负margin的实践有很多,但对margin负值为什么会出现这样的效果却没有多少讲解,本篇的目的就是阐述 ...
- css margin的相关属性,问题及应用
by zhangxinxu from http://www.zhangxinxu.com本文地址:http://www.zhangxinxu.com/wordpress/?p=48 引言:margin ...
- clear:both后margin-top不起作用
如: <div style="float:left;">float:left</div> <div style="clear:both;ma ...
随机推荐
- Java基础学习总结(18)——网络编程
一.网络基础概念 首先理清一个概念:网络编程 != 网站编程,网络编程现在一般称为TCP/IP编程. 二.网络通信协议及接口 三.通信协议分层思想 四.参考模型 五.IP协议 每个人的电脑都有一个独一 ...
- 概率dp HDU 3853
H - LOOPS Time Limit:5000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit ci ...
- Track Active Item in Solution Explorer
Tools-->Options-->Projects and Solutions-->Track Active Item in Solution Explorer
- export和source的区别
1.执行脚本是在一个子shell环境运行的,脚本执行完后该子shell自动退出. 2.执行脚本中的系统环境变量(用export定义的变量)才会被复制到子shell中. 3.一个shell中的系统环境变 ...
- OpenSUSE42.3 leap 软件源设置
一.OpenSUSE软件源介绍: 1.默认已经加入了官方的软件源,不过我们自己也可以根据需要添加很多非官方软件源,添加软件源时要注意: 非官方源可能包含一些试验中的不稳定的软件包 不同的软件源之 ...
- 网络爬虫与web之间的访问授权协议——Robots
网站的管理者们通常会有这样一种心态:一方面期待百度.Google这样的搜索引擎来抓取网站的内容,另一方面又很厌恶其他来路不明的网络爬虫抓取自己的信息.正是因为这样,才有“好爬虫”.“坏爬虫”这样的说法 ...
- React开发实时聊天招聘工具 -第五章 需求分析
Axios的使用 axios.get('/data') .then(res=>{ if(res.status==200) this.setState(data:res.data) })
- 【Django】Cookie
目录 Cookie介绍 操作Cookie 获取Cookie 设置 Cookie 删除Cookie @ Cookie介绍 Cookie的由来 大家都知道==HTTP协议是无状态的==. ==无状态的的意 ...
- Unityclient通信測试问题处理(一)
Unityclient通信測试问题处理(一) 近期在測试程序的通信模块时.遇到了一个问题:Unity的API函数仅仅能在主线程中调用.而作为client程序,我单独启用了一个监听线程来接收服务端发送的 ...
- POJ 1328 Radar Installation 贪心题解
本题是贪心法题解.只是须要自己观察出规律.这就不easy了,非常easy出错. 一般网上做法是找区间的方法. 这里给出一个独特的方法: 1 依照x轴大小排序 2 从最左边的点循环.首先找到最小x轴的圆 ...