Android ProgressBar 使渐变渐变透明

Android ProgressBar make gradient fade transparent

目前是my ProgressBar

注意粉红色如何逐渐变成背景色。这不仅仅是因为背景是灰色的(这只是 Android Studio 中布局预览的一个片段),因为即使在具有白色背景的应用程序中它仍然会淡化为黑色。

我想要实现的是粉红色逐渐变为透明,因此随着渐变中粉红色数量的减少,更多的背景变得可见。

有人知道如何实现吗?

这是进度条的可绘制对象:

<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromDegrees="0"
    android:pivotX="50%"
    android:pivotY="50%"
    android:toDegrees="360">

    <shape
        android:innerRadiusRatio="3"
        android:shape="ring"
        android:thicknessRatio="30"
        android:useLevel="false">

    <gradient
        android:centerColor="#00000000"
        android:centerY="0.50"
        android:endColor="@color/colorAccent"
        android:startColor="@color/colorAccent"
        android:type="sweep"
        android:useLevel="false" />
   </shape>

这是它在我的布局中的声明:

 <ProgressBar
     android:layout_width="210sp"
     android:layout_height="210sp"
     style="?android:attr/progressBarStyleLarge"
     android:indeterminateDrawable="@drawable/circular_progress_bar_big"
     android:indeterminate="false"
     android:id="@+id/progressPose"
     android:layout_gravity="center"
     android:visibility="visible"
     android:progress="100" />

感谢大家的帮助,谢谢! 最大值

对于颜色的透明度使用了这个答案Hex transparency in colors

  • 100% — FF
  • 95% — F2
  • 90% — E6
  • 85% — D9
  • 80% — CC
  • 75% — 高炉
  • 70% — B3
  • 65% — A6
  • 60% — 99
  • 55% — 8C
  • 50% — 80
  • 45% — 73
  • 40% — 66
  • 35% — 59
  • 30% — 4D
  • 25% — 40
  • 20% — 33
  • 15% — 26
  • 10% — 1A
  • 5% — 0D
  • 0% — 00

(source)

所以在你的 drawable 中,你设置了透明度,就像颜​​色强调一样

 <?xml version="1.0" encoding="utf-8"?>
 <rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="360">

<shape
    android:innerRadiusRatio="3"
    android:shape="ring"
    android:thicknessRatio="30"
    android:useLevel="false">

<gradient
    android:centerColor="#00000000"
    android:centerY="0.50"
    android:endColor="@color/colorAccent"
    android:startColor="@color/colorAccent"
    android:type="sweep"
    android:useLevel="false" />
  </shape>
</rotate>

color.xml

50%

  <color name="colorAccent">#80FF4081</color>

85% — D9

  <color name="colorAccent">#D9FF4081</color>

等你用...