0

I want to create the following drawable dinamically to use it inside a Circle Progress bar:

<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:pivotX="50%"
android:pivotY="50%"
android:fromDegrees="0"
android:toDegrees="720">

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

    <gradient
        android:type="linear"
        android:useLevel="false"
        android:startColor="@android:color/transparent"
        android:centerColor="@color/colorAccent"
        android:endColor="@android:color/black"
        android:angle="45" />
</shape>

I have to create it dynamically due is required to change the startColor/centerColor/endColor in execution time.

Thanks in advance for your responses.

MarcForn
  • 3,321
  • 7
  • 25
  • 39
  • I guess you can change the gradient colors only. http://developer.android.com/reference/android/graphics/drawable/GradientDrawable.html#setColors(int[]) – Phantômaxx Oct 12 '15 at 11:06
  • if you want to create it java make a custom `Shape` class and use it in a `ShapeDrawable` constructor – pskink Oct 12 '15 at 11:17
  • The problem I'm getting is doing that I don't get a RotateDrawable, so my progressbar does not spin. – MarcForn Oct 12 '15 at 11:18
  • 1
    so use a "base" `Drawable` and animate it either with an `[Object|Value|Time]Animator` or via `invalidateSelf` / `scheduleSelf` – pskink Oct 12 '15 at 11:21
  • Cna you provide me further information about how to do that? Thanks – MarcForn Oct 16 '15 at 18:25
  • @pskink can you provide a snippet about how tot do that? I'm thinking on create a Layer Drawable with the following layers (backgroun, gradient, circle) and then rotate the entire view. I'm in the right way? Thanks – MarcForn Oct 16 '15 at 19:25
  • create a class that extends Drawable, pass all the layers via a constructor, then in draw() method draw em all – pskink Oct 16 '15 at 19:31
  • @pskink: finally I have reached a kind of solution but now I'm facing a problem when trying to set the GradientDrawable inside a bitmap on onDraw method. I've opened the following question to get more help about that (http://stackoverflow.com/questions/33181417/convert-gradientdrawable-to-bitmap). So I think this thread can be closed. – MarcForn Oct 17 '15 at 00:32

0 Answers0