形状填充在 6 Android 之前不起作用
Shape padding not working pre 6 Android
形状填充似乎在 pre 6 Android 上不起作用。我正在尝试向自定义 ProgressBar
背景渐变添加填充,而我拥有的是:
Android6.0:
Android 5.0 及以下:
pb_shape.xml
:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background">
<shape android:shape="rectangle">
<corners android:radius="12dip" />
<stroke
android:width="1dip"
android:color="@color/primary_white" />
<gradient
android:angle="270"
android:centerColor="@color/primary_black"
android:centerY="0.5"
android:endColor="@color/primary_black"
android:gradientRadius="12dip"
android:startColor="@color/primary_black" />
<!--This not working pre 6 android-->
<padding
android:bottom="4dp"
android:left="4dp"
android:right="4dp"
android:top="4dp" />
</shape>
</item>
<item android:id="@android:id/progress">
<clip>
<shape>
<corners android:radius="12dip" />
<gradient
android:angle="0"
android:endColor="@color/primary_teal"
android:startColor="@color/primary_blue_dark" />
</shape>
</clip>
</item>
我已经尝试将这两个项目包装在不同的 xml 文件中并在那里设置填充,但它没有效果:
<item
android:bottom="4dp"
android:left="4dp"
android:right="4dp"
android:top="4dp"
android:drawable="@drawable/pb_gradient_bg"
/>
知道是什么原因导致了这种行为吗?解决方案是什么?
看来我找到了解决方法。需要为具有所需宽度的渐变创建透明描边,而它正是需要的。
有关解决方案,请查看我在
中的答案
编码愉快:)
形状填充似乎在 pre 6 Android 上不起作用。我正在尝试向自定义 ProgressBar
背景渐变添加填充,而我拥有的是:
Android6.0:
Android 5.0 及以下:
pb_shape.xml
:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background">
<shape android:shape="rectangle">
<corners android:radius="12dip" />
<stroke
android:width="1dip"
android:color="@color/primary_white" />
<gradient
android:angle="270"
android:centerColor="@color/primary_black"
android:centerY="0.5"
android:endColor="@color/primary_black"
android:gradientRadius="12dip"
android:startColor="@color/primary_black" />
<!--This not working pre 6 android-->
<padding
android:bottom="4dp"
android:left="4dp"
android:right="4dp"
android:top="4dp" />
</shape>
</item>
<item android:id="@android:id/progress">
<clip>
<shape>
<corners android:radius="12dip" />
<gradient
android:angle="0"
android:endColor="@color/primary_teal"
android:startColor="@color/primary_blue_dark" />
</shape>
</clip>
</item>
我已经尝试将这两个项目包装在不同的 xml 文件中并在那里设置填充,但它没有效果:
<item
android:bottom="4dp"
android:left="4dp"
android:right="4dp"
android:top="4dp"
android:drawable="@drawable/pb_gradient_bg"
/>
知道是什么原因导致了这种行为吗?解决方案是什么?
看来我找到了解决方法。需要为具有所需宽度的渐变创建透明描边,而它正是需要的。
有关解决方案,请查看我在
编码愉快:)