Sna*_*ake 5 android android-animation
我想知道如何做到以下几点.我希望我的应用程序背景能够被动画化(让我们说鸟类飞行的是什么样的活壁纸看起来像).这通常是使用GIF背景完成还是我需要编写动画或使用绘画/绘图功能来绘制动画(我希望不是!)
任何指针都很受欢迎,因为我不知道该怎么做
谢谢
小智 8
你也可以使用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"
/>
Run Code Online (Sandbox Code Playgroud)
在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();
}
}
Run Code Online (Sandbox Code Playgroud)
在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>
Run Code Online (Sandbox Code Playgroud)
希望这可能对你有所帮助
| 归档时间: |
|
| 查看次数: |
8593 次 |
| 最近记录: |