FrameLayout margin not working

问题:在2.3版本手机上 FrameLayout  中view 设置 margin  无效

解决:

I had the same issue myself and noticed that setting the layout_ margins does not work until you also set your ImageView's layout gravity i.e. android:layout_gravity="top" in the XML resource file, or from code: FrameLayout.LayoutParams.gravity = Gravity.TOP;.


原因:

To make it more clear why. The FrameLayout.onLayout() call contains this (in api v2.3.4 at least): // for each child: final LayoutParams lp = (LayoutParams) child.getLayoutParams(); final int gravity = lp.gravity; if (gravity != -1) { // handle all margin related stuff  So if gravity is -1, there will be no margin calculation. Gravity in FrameLayout.LayoutParams is defined by: gravity = a.getInt(com.android.internal.R.styleable.FrameLayout_Layout_layout_gravity, -1);  So if gravity is not set, there will be no margin calculation.


链接:

http://stackoverflow.com/questions/5401952/framelayout-margin-not-working#


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值