下载了ADW_Launcher的源码,ADW_Launcher在原Launcher中加入了很多功能。比如说Dock,预览编辑Screen,分页显示,显示隐藏任务栏等等,功能多用户的选择就多,但操作过于复杂。所以在原先的功能上进行了很多修改。将操作简洁。为了增加娱乐性和用户体验,现在要在statusBar隐藏显示的时候播放一段动画。好了,废话少说,请看代码
(1) 下载一张gif图片,使用Ulead GIF Animator 5处理成png图片。
将处理过后的图片拷贝到工程的drawable文件中。
(2) 在anim文件夹中新建statusbar_animation.xml文件。
<?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/anim001" android:duration="80"/> <item android:drawable="@drawable/anim002" android:duration="80"/> <item android:drawable="@drawable/anim003" android:duration="80"/> <item android:drawable="@drawable/anim004" android:duration="80"/> <item android:drawable="@drawable/anim005" android:duration="80"/> <item android:drawable="@drawable/anim006" android:duration="80"/> <item android:drawable="@drawable/anim007" android:duration="80"/> </animation-list>
(3)分别在layout-land和layout-port文件夹下的launcher.xml文件中添加如下代码:
<com.android.launcher.StatusBarAnimation android:id="@+id/statusbar_anim" android:background="@anim/statusbar_animation" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="top|left"/>
(4)在com.android.launcher包下新建StatusBarAnimation.java类,这个类只需要继承LinearLayout即可
package com.android.launcher; import android.content.Context; import android.util.AttributeSet; import android.widget.LinearLayout; public class StatusBarAnimation extends LinearLayout{ private Launcher mLauncher; private DragController mDragger; public void setLauncher(Launcher mLauncher) { this.mLauncher = mLauncher; } public void setDrager(DragController mDragger) { this.mDragger = mDragger; } public StatusBarAnimation(Context context) { super(context); } public StatusBarAnimation(Context context, AttributeSet attrs) { super(context, attrs); } }
(5)修改Launcher.java
a) 在Launcher.java文件中定义成员变量
// StartBar animation private StatusBarAnimation mStatusBarAnimation; private AnimationDrawable mAnimationDrawable;
b) 在setupViews中添加如下代码
mStatusBarAnimation =(StatusBarAnimation) findViewById(R.id.statusbar_anim); final StatusBarAnimation statusBarAnimation = mStatusBarAnimation; statusBarAnimation.setLauncher(this); statusBarAnimation.setDrager(dragLayer);
c) 在你需要启动动画的地方启动即可,代码如下
mAnimationDrawable = (AnimationDrawable) mStatusBarAnimation.getBackground(); mAnimationDrawable.start();
关于Android动画的资料网上多如牛毛,各位细心寻找。定能寻获,这里不再详述。这里只是给出在Launcher上动画的效果,具体很多细节按需求修改了。