gpt4 book ai didi

android - 背景动画图像

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:21:32 24 4
gpt4 key购买 nike

我想知道如何执行以下操作。我希望我的应用程序背景具有动画效果(比方说飞翔的鸟儿有点像动态墙纸的样子)。这通常是使用 GIF 背景完成的,还是我需要编写动画代码或使用绘画/绘制功能来绘制动画(我希望不需要!)

感谢任何指点,因为我不确定该怎么做

谢谢

最佳答案

您也可以使用 GIF 图像来完成此操作,但首先要将该 GIF 转换为帧

在 xml 中

<ImageView 
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/img1"
/>

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/img1"
android:layout_centerHorizontal="true"
android:layout_marginTop="156dp"
android:text="submit"
/>

在Java中

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

ImageView i = (ImageView)findViewById(R.id.img1);
i.setBackgroundResource(R.drawable.gif);

AnimationDrawable pro = (AnimationDrawable)i.getBackground();
pro.start();
}
}

在drawable中创建动画文件

<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/selected" android:oneshot="false">
<item android:drawable="@drawable/frame0" android:duration="50" />
<item android:drawable="@drawable/frame1" android:duration="50" />
<item android:drawable="@drawable/frame2" android:duration="50" />
<item android:drawable="@drawable/frame3" android:duration="50" />
<item android:drawable="@drawable/frame4" android:duration="50" />
<item android:drawable="@drawable/frame5" android:duration="50" />
<item android:drawable="@drawable/frame6" android:duration="50" />
<item android:drawable="@drawable/frame7" android:duration="50" />
<item android:drawable="@drawable/frame8" android:duration="50" />
<item android:drawable="@drawable/frame8" android:duration="50" />
<item android:drawable="@drawable/frame9" android:duration="50" />
<item android:drawable="@drawable/frame10" android:duration="50" />

</animation-list>

希望对你有帮助

关于android - 背景动画图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18929681/

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