leandroBorgesFerreira / LoadingButtonAndroid

A button to substitute the ProgressDialog
MIT License
1.94k stars 214 forks source link

Is it possible to align the loader into the center if the width of the button is bigger when the loading started. #135

Open gbrbks opened 5 years ago

gbrbks commented 5 years ago

Hey!

My plan is to modify the library to have a certain width when the loading started. Actually removed the width animation to stay in the original width. However, in this scenario, the loader is drawn at the left side of the button, not in the center. Is there any way to move it to the center?

Thanks in advance!

bennnjamin commented 4 years ago

Hello, I have this same requirement and spent some time figuring it out. You will have to fork/clone the project to do this. The file you need to edit is CircularProgressAnimatedDrawable.kt in the fun onDraw(canvas: Canvas) method you need to add this line:

canvas.translate((progressButton.getWidth() - progressButton.finalWidth)/2f, 0f)

See the file here: https://github.com/leandroBorgesFerreira/LoadingButtonAndroid/blob/bc24bfe276bfb6bd3f76cd6e38af877d24802893/loading-button-android/src/main/java/br/com/simplepass/loadingbutton/animatedDrawables/CircularProgressAnimatedDrawable.kt#L164

Make sure the function is now like this:

   override fun draw(canvas: Canvas) {
        val (startAngle, sweepAngle) = getAngles()
        canvas.translate((progressButton.getWidth() - progressButton.finalWidth)/2f, 0f)
        canvas.drawArc(fBounds, startAngle, sweepAngle, false, paint)
    }