FrameLayout margin not working

后端 未结 7 1874
野的像风
野的像风 2020-12-04 09:46

My layout structure is like this

LinearLayout
    FrameLayout
       ImageView
       ImageView
    FrameLayout
    TextView
LinearLayout

I

相关标签:
7条回答
  • 2020-12-04 10:25

    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. And the thing is, 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.

    0 讨论(0)
提交回复
热议问题