无法在进度条上应用光晕效果



我正在尝试在进度条上应用辉光效果。我使用png图像来显示光晕效果,但随着加载的进行,它不会移动。如果有任何帮助,我们将不胜感激。谢谢

mydrawable.xml:-

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@android:id/background"
      >
        <shape>
            <corners android:radius="20dip"
               />
            <gradient
                    android:startColor="#434343"
                    android:centerColor="#ffffff"
                   android:endColor="#434343"
                    android:angle="270"

            />
            <!-- gradient
                    android:startColor="#ff9d9e9d"
                    android:centerColor="#ff5a5d5a"
                    android:centerY="0.75"
                    android:endColor="#ff747674"
                    android:angle="270"
                     android:centerColor="#0040F8"
                     android:endColor="#00F810"
          /-->
        </shape>
    </item>
    <item android:id="@android:id/secondaryProgress">
        <clip>
            <shape>
                <corners android:radius="20dip" />
                <gradient
                        android:startColor="#F80070"
                        android:centerColor="#00F810"
                        android:centerY="0.75"
                        android:endColor="#F88000"
                        android:angle="270"
                />
            </shape>
        </clip>
    </item>
 <item android:id="@android:id/progress">
        <clip>
            <shape>
                <corners android:radius="20dip" />
                <gradient
                        android:startColor="#F80070"
                        android:centerColor="#FFFF00"
                        android:centerY="0.75"
                        android:endColor="#F88000"
                        android:angle="0"
                />
            </shape>
        </clip>
    </item>
 <item >
    <bitmap
        android:antialias="true"
        android:gravity="right|bottom|fill_vertical"
        android:src="@drawable/glow1" />
</item>   
</layer-list>

您必须在xml中使用drawable,如下所示:

<item android:id="@android:id/progress">
        <scale android:scaleWidth="100%"
               android:drawable="@drawable/glow1" />
    </item>

通过代码可以这样做。

progressBar.setProgressDrawable(getShapeWithGlow(
                progressBar,
                progressBar.getResources().getColor(R.color.gradient_white, null),
                progressBar.getResources().getColor(R.color.color_white, null)));

public static Drawable getShapeWithGlow(View view, int backgroundColor, int glowColor) {
    ShapeDrawable shapeDrawable = new ShapeDrawable();
    shapeDrawable.getPaint().setColor(backgroundColor);
    shapeDrawable.getPaint().setShadowLayer(13, 0, 0,
            glowColor); //      To create shadow like background glow
    view.setLayerType(LAYER_TYPE_SOFTWARE, null); // To display the glow need to set Layer type.
    InsetDrawable insetDrawable = new InsetDrawable(shapeDrawable, 0, 10, 0, 10);
    LayerDrawable layerDrawable = new LayerDrawable(new Drawable[]{insetDrawable, shapeDrawable});
    layerDrawable.setLayerInset(1, 0, 8, 0, 8);
    ClipDrawable drawableProgress = new ClipDrawable(layerDrawable, Gravity.START, ClipDrawable.HORIZONTAL);
    return drawableProgress;
}

相关内容

  • 没有找到相关文章

最新更新