gpt4 book ai didi

android - 如何为图层列表中的一项设置动画

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:13:37 26 4
gpt4 key购买 nike

我有一个图层列表对象,它包含两个图像,一个是背景,另一个是旋转磁盘图像,将在背景图像的顶部。即我使用这个图层列表作为线性布局背景,我只想为图层列表的“disk_bg”项设置动画;

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/
android">
<item android:drawable="@drawable/player_bg" />

<item android:top="166dp" >
<bitmap android:id="@+id/disk_bg" android:src="@drawable/cd"
android:gravity="center" />
</item>

我使用这个图层列表作为布局背景,你知道如何在我的应用程序中为 disk_bg 图层设置动画吗?

你能帮帮我吗,非常感谢你~

你不明白我的问题吗?还是没有办法做到这一点?

最佳答案

首先创建 2(或更多)层列表资源,即 *layer_frame1.xml* 和 *layer_frame2.xml* ,您可以在其中设置框架。在您的情况下,假设更改磁盘项目的 android:top。

然后创建一个动画列表资源,您可以在其中设置帧的时间和顺序:

<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="false">

<item
android:drawable="@drawable/layer_frame1"
android:duration="100"/>
<item
android:drawable="@drawable/layer_frame2"
android:duration="100"/>

</animation-list>

将其保存在文件中,即 *drawable/player_animation.xml* 并将其设置为 View 上的背景

<View
android:id="@+id/animation_test"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/player_animation" />

最后在你的代码中说明你希望动画何时开始。

 ((AnimationDrawable)findViewById(R.id.animation_test).getBackground()).start();

注意不要onCreate() 方法中启动动画。

关于android - 如何为图层列表中的一项设置动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5777225/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com