Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: What is the use of padding in shape drawables?

I try to understand the default background of Button (android 26).

sdk/platforms/android-26/data/res/drawable/btn_default_material.xml

<ripple xmlns:android="http://schemas.android.com/apk/res/android"
        android:color="?attr/colorControlHighlight">
    <item android:drawable="@drawable/btn_default_mtrl_shape" />
</ripple>

references:

sdk/platforms/android-26/data/res/drawable/btn_default_mtrl_shape.xml:

<?xml version="1.0" encoding="utf-8"?>
<inset xmlns:android="http://schemas.android.com/apk/res/android"
       android:insetLeft="@dimen/button_inset_horizontal_material"
       android:insetTop="@dimen/button_inset_vertical_material"
       android:insetRight="@dimen/button_inset_horizontal_material"
       android:insetBottom="@dimen/button_inset_vertical_material">
    <ripple android:color="?attr/colorControlHighlight">
        <item>
            <shape android:shape="rectangle"
                   android:tint="@color/btn_colored_background_material">
                <corners android:radius="@dimen/control_corner_material" />
                <solid android:color="@color/white" />
                <padding android:left="@dimen/button_padding_horizontal_material"
                         android:top="@dimen/button_padding_vertical_material"
                         android:right="@dimen/button_padding_horizontal_material"
                         android:bottom="@dimen/button_padding_vertical_material" />
            </shape>
        </item>
    </ripple>

</inset>

I understand the inset. That is the space around the button background image. I don't understand the padding. There is no text in the background image.

To give an approach to think about it: What would happen if you remove the padding tag?

You may come to the conclusion that nothing would happen (I am not sure, that nothing would happen). But if nothing happens, you have the question what is it useful for? Why did they place it there?

like image 945
Blcknx Avatar asked Jun 02 '18 10:06

Blcknx


People also ask

What is the use of padding in android?

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 number 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.

What is drawable padding?

android:drawablePadding is used for space between image and text.

What are Drawables in android?

A drawable resource is a general concept for a graphic that can be drawn to the screen and which you can retrieve with APIs such as getDrawable(int) or apply to another XML resource with attributes such as android:drawable and android:icon . There are several different types of drawables: Bitmap File.

What is drawable shape android?

The Shape Drawable is an XML file that defines a geometric shape, including colors and gradients. This is used to create a complex shape that can then be attached as the background of a layout or a view on screen.


1 Answers

This padding will be applied to the view to which you set the background on top of the actual padding applied. If you set this background to buttons, then the text area will be reduces by this amount.

like image 173
Bertram Gilfoyle Avatar answered Oct 04 '22 22:10

Bertram Gilfoyle