Get android:padding attribute programmatically

前端 未结 3 1638

From a view, how can I get the value of the android:padding attribute programmatically? I am currently using:

private static final String ANDROID_NAMESPACE = \"h         


        
3条回答
  •  佛祖请我去吃肉
    2021-02-07 06:42

    You should look at the getPadding____() functions.

    Size, padding and margins

    ...

    To measure its dimensions, a view takes into account its padding. The padding is expressed in pixels for the left, top, right and bottom parts of the view. Padding can be used to offset the content of the view by a specific amount of pixels. For instance, a left padding of 2 will push the view's content by 2 pixels to the right of the left edge. Padding can be set using the setPadding(int, int, int, int) or setPaddingRelative(int, int, int, int) method and queried by calling getPaddingLeft(), getPaddingTop(), getPaddingRight(), getPaddingBottom(), getPaddingStart(), getPaddingEnd().

    Even though a view can define a padding, it does not provide any support for margins. However, view groups provide such a support. Refer to ViewGroup and ViewGroup.MarginLayoutParams for further information.

提交回复
热议问题