1

I'm trying to create an animation which gets a percentage value (0-100) and stretches a thick line in a curve according to the value, where 100% is a full circle, 50% is half a circle and so on.

I've added a view to be my starting line:

<View
    android:id="@+id/testAnimationView"
    android:layout_width="30dp"
    android:layout_height="50dp"
    android:layout_gravity="center"
    android:background="#FF000000" />

I've tried creating a ScaleAnimation on the View but it seems I only succeed to make a "straight line" animation where the X and Y are stretched to create a bigger square, but it's not what I need..

How can I create an animation which starts with a very thin line and stretches it to a circle with the percentage value?

CodeMonkey
  • 11,196
  • 30
  • 112
  • 203

2 Answers2

1

try integrating samples projects in your code

https://github.com/lzyzsd/CircleProgress

https://github.com/lopspower/CircularProgressBar

Ajay Venugopal
  • 1,544
  • 1
  • 17
  • 30
1

as Ajay Venugopal said you can use CircularProgressBar.java from https://github.com/lopspower/CircularProgressBar/blob/master/circularprogressbar/src/main/java/com/mikhaellopez/circularprogressbar/CircularProgressBar.java

The only change you have to do in CircularProgressBar.java is:

Line 64:

foregroundPaint.setStyle(Paint.Style.FILL);

Line 75:

canvas.drawArc(rectF, startAngle, angle, true, foregroundPaint);

in your layout

<CircularProgressBar
        style="?android:attr/progressBarStyle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:cpb_background_progressbar_color="#b6bbd8"
        app:cpb_background_progressbar_width="10dp"
        app:cpb_progressbar_color="#3f51b5"
        app:cpb_progressbar_width="20dp"
        android:id="@+id/progressBar" />

then in your MainActivity.java

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        final CircularProgressBar circularProgressBar = (CircularProgressBar) findViewById(R.id.progressBar);
        circularProgressBar.setProgressWithAnimation(65, 4000);

}
Tihomir Tashev
  • 185
  • 2
  • 9