问题:在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#

本文解决了在2.3版本手机上FrameLayout中view设置margin无效的问题。通过设置ImageView的layout_gravity为top,可以成功应用margin。若不设置gravity,则FrameLayout不会计算margin。
134

被折叠的 条评论
为什么被折叠?



