Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LottieDrawable set bounds not working #1079

Closed
zhangruize opened this issue Jan 8, 2019 · 8 comments
Closed

LottieDrawable set bounds not working #1079

zhangruize opened this issue Jan 8, 2019 · 8 comments

Comments

@zhangruize
Copy link

zhangruize commented Jan 8, 2019

For some special reasons, I need to use LottieDrawable like View.getOverlay().add(lottieDrawable). But I found the animation content cannot be positioned in center though I set correct bounds via lottieDrawable.setBounds(...) after lottie composition loaded.

Is there any way to center LottieDrawable in View.getOverlay() ?

@zhangruize
Copy link
Author

zhangruize commented Jan 8, 2019

I've found a not quite good solution. I override draw method of LottieDrawable, and translate the canvas as I want. Is there any better idea?

I'm not using the latest version of Lottie. If the latest have support this perfectly, it's ok, if not, maybe LottieDrawable should support something like translate the canvas of animation content.

@gpeal
Copy link
Collaborator

gpeal commented Jan 10, 2019

@zhangruize Can you attach a sample project?

@gpeal
Copy link
Collaborator

gpeal commented Feb 3, 2019

I think translating for your specific use case is fine. Most of the time, ImageView scaleType is what you would use to achieve this.

@gpeal gpeal closed this as completed Feb 3, 2019
@Krishna-Vyas
Copy link

I'm also trying to setBounds on LottieDrawable, but it's not working.
When I scale LottieDrawable with setScale(), it setBounds to (0,0,width,height)
but I want to set animation on the bottom-right corner of the drawable. And This work is not UI
related, So I can't set scaleType on LottieAnimationView. Please tell me how can scale drawable to stay at the bottom-right corner.

@irgaly
Copy link

irgaly commented Feb 17, 2021

I'm facing same issue with View.getOverlay().add(lottieDrawable).
Calling LottieDrawable.setBounds(x, y, width, height) does not affect. The animation always appears left top corner of View Overlay.

@irgaly
Copy link

irgaly commented Feb 17, 2021

my workaround, same approach as @zhangruize

class PositionedLottieDrawable : LottieDrawable() {
    var x: Float = 0f
    var y: Float = 0f
    override fun draw(canvas: Canvas) {
        canvas.save()
        canvas.translate(x, y)
        super.draw(canvas)
        canvas.restore()
    }
}

@gpeal
Copy link
Collaborator

gpeal commented Feb 17, 2021

@Krishna-Vyas @irgaly What version of Lottie? 3.6.0 should respect the bounds you set

@irgaly
Copy link

irgaly commented Feb 18, 2021

I'm using 3.4.0.

I tried Lottie 3.6.1, but the animation appeared at (0, 0).
Here is my code, and I tested it in Android 9.

private val drawable = LottieDrawable()
...
// I watched with debugger, they are x = 792, y = 161 here. 
drawable.setBounds(x, y, drawable.composition.bounds.right + x, drawable.composition.bounds.bottom + y)
targetView.overlay.add(drawable)
drawable.playAnimation()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants