形状填充不适用于6 Android之前

时间:2016-05-10 13:46:17

标签: android android-layout android-progressbar android-shape

似乎形状填充不适用于pre 6 Android。我正在尝试将填充添加到自定义ProgressBar背景渐变以及我拥有的内容:

Android 6.0:

enter image description here

Android 5.0及以下版本:

enter image description here

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文件中并在那里设置padding,但它不起作用:

 <item
    android:bottom="4dp"
    android:left="4dp"
    android:right="4dp"
    android:top="4dp"
    android:drawable="@drawable/pb_gradient_bg"
    />

任何想法导致此行为的原因以及可能的解决方案是什么?

1 个答案:

答案 0 :(得分:0)

好像我找到了解决方法。需要为具有所需宽度的渐变创建透明笔划,并且它确实完成了所需的操作。

要解决方案,请在similar question here

中查看我的答案

快乐编码:)