我试着理解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>
参考文献:
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>
我理解插图。这是按钮背景图像周围的空间。我不明白填充物的意思。背景图像中没有文本。
给出一种思考它的方法:如果删除padding
标记会发生什么?
你可能会得出什么都不会发生的结论(我不确定,什么都不会发生)。但是如果什么都没有发生,你就会有一个问题:它有什么用呢?他们为什么把它放在那里?
发布于 2018-06-08 12:45:58
此填充将应用于在实际应用的填充之上设置背景的视图。如果您将此背景设置为按钮,则文本区域将减少此量。
发布于 2018-06-02 19:02:23
但是你要在按钮中输入文本,在你的按钮文本周围必须有特定的填充,试着设置你自己的背景,然后设置大文本,在你的文本周围没有填充,这是为了按钮的外观和感觉。
发布于 2018-06-04 23:45:21
填充只适用于任何容器,如果您在任何布局中使用填充,它将为您提供所需的空间。
如果你想在内容周围留出空格,只需使用android:padding
即可,否则你可以自定义填充。如果您正在使用没有任何布局或容器的填充,那么它将不起作用。在这种情况下,唯一有效的方法就是保证金。
https://stackoverflow.com/questions/50656147
复制相似问题