LoadingButtonAndroid icon indicating copy to clipboard operation
LoadingButtonAndroid copied to clipboard

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

Open gbrbks opened this issue 6 years ago • 1 comments

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!

gbrbks avatar May 16 '19 09:05 gbrbks

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)
    }

bennnjamin avatar Sep 30 '19 17:09 bennnjamin