简体   繁体   English

Lottie Animation 中的动态文本更改其 position

[英]Dynamic Text in Lottie Animation changes its position

I was wondering how to dynamically enter a text in your Lottie animations.我想知道如何在 Lottie 动画中动态输入文本。 Everything pointed me to TextDelegate.一切都指向了 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.我确实有一个 animation,当我使用文本委托时,文本的 position 在 Y 轴上变化 50-60 像素,在 X 轴上变化 20-30 像素。

I was wondering are there any guidelines on how to create Lottie animations that support dynamic text.我想知道是否有关于如何创建支持动态文本的 Lottie 动画的指南。 I can't even find other Lottie examples that support dynamic text.我什至找不到其他支持动态文本的 Lottie 示例。 So at this point I'm confused on whether is it the way the Lottie JSON I have or is it my code.所以在这一点上,我很困惑是我拥有的 Lottie JSON 还是我的代码。

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: OP的解决方案从评论迁移到答案:

I managed to fix this but it was kind of a hack.我设法解决了这个问题,但这是一种黑客行为。 Usually text in your lottie file will be "t": "Random Text ".通常,您的 lottie 文件中的文本将是"t": "Random Text ”。 So you update the JSON during run time.因此,您在运行时更新 JSON。 It's not perfect.这并不完美。 val newLottieJson = oldJson.replace("\"t\": \"Random Text,\"": "\"t\".\"${nameEditText.text}\"") . val newLottieJson = oldJson.replace("\"t\": \"Random Text,\"": "\"t\".\"${nameEditText.text}\"")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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