Get margin of a View

前端 未结 4 1061
遇见更好的自我
遇见更好的自我 2021-01-31 13:28

How can I get the margin value of a View from an Activity? The View can be of any type.

After a bit of searching I found out ways to get padding of a view, but couldn\'

4条回答
  •  忘了有多久
    2021-01-31 13:40

    Try

    ViewGroup.MarginLayoutParams vlp = (MarginLayoutParams) view.getLayoutParams()
    
    vlp.rightMargin
    vlp.bottomMargin
    vlp.leftMargin
    vlp.topMargin
    

    This returned the correct margains for my view atleast.

    http://developer.android.com/reference/android/view/ViewGroup.MarginLayoutParams.html

提交回复
热议问题