简体   繁体   中英

Dynamic Text in Lottie Animation changes its position

I was wondering how to dynamically enter a text in your Lottie animations. Everything pointed me to TextDelegate.

I do have an animation and when i use text delegate, the position of the text changes with 50-60 pixels off on Y axis and 20-30 pixels on X axis.

I was wondering are there any guidelines on how to create Lottie animations that support dynamic text. I can't even find other Lottie examples that support dynamic text. So at this point I'm confused on whether is it the way the Lottie JSON I have or is it my code.

Here's a straightforward snippet:

 fun useTextDelegate(text: String) {
    textDelegate = TextDelegate(dynamicTextView)
    textDelegate.setText("Good Morning!", text)
    dynamicTextView.setTextDelegate(textDelegate)
    dynamicTextView.playAnimation()
}

Use Case: Good Morning / Good Evening / Good Night. Depending on the time, I want to change the text.

Solution from OP migrated from comments to an answer:

I managed to fix this but it was kind of a hack. Usually text in your lottie file will be "t": "Random Text ". So you update the JSON during run time. It's not perfect. val newLottieJson = oldJson.replace("\"t\": \"Random Text,\"": "\"t\".\"${nameEditText.text}\"") .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM