LinearLayout, RelativeLayout, etc. margins do not work as expected

前端 未结 4 1714
你的背包
你的背包 2021-02-05 05:06

Margins in group layouts do not seem to work.

For example,




        
4条回答
  •  面向向阳花
    2021-02-05 06:01

    The problem is actually the way FrameLayout interprets margins. setContentView() attaches your "main" layout to a FrameLayout, which is the actual root of the view hierarchy (you can see that with Hierarchy Viewer) and is offered to you by the phone.

    Margins are managed by the parent layout, so in this case that main FrameLayout. I don't know if it's a feature or a bug, but that's how this layout interprets margins.

    So well, the solution was already posted while I was typing: use padding instead.

提交回复
热议问题