要在Android应用中播放Lottie动画,你可以按照以下步骤进行操作:
dependencies {
implementation 'com.airbnb.android:lottie:3.7.0'
}
将Lottie动画文件放入assets文件夹:将要播放的Lottie动画文件(例如animation.json)放入项目的assets文件夹中。
在布局文件中添加LottieView:在你的布局文件中添加一个LottieView来显示动画。
import com.airbnb.lottie.LottieAnimationView;
public class MainActivity extends AppCompatActivity {
private LottieAnimationView animationView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
animationView = findViewById(R.id.animation_view);
animationView.setAnimation("animation.json");
animationView.playAnimation();
}
}
这样就可以在你的应用中播放Lottie动画了。记得将"animation.json"替换为你的实际动画文件的名称。