View Animation
- AlphaAnimation 淡入淡出效果
- TranslateAnimation 移动效果
- ScaleAnimation 缩放效果
- RotateAnimation 旋转效果
原理:提供动画的起始和结束状态信息,中间的状态根据上述类里差值器算法填充
[示例参考]
Property Animation
View Animation动画比较简单,一般都是单个因素的变化,如果牵扯到复杂的动画,就显得力不从心。因此,Android 3.0 引入了属性动画。注:可通过[NineOldAndroids]项目在3.0之前的系统中使用Property Animation
原理:暴露出差值算法的回调方法,有工程师自己发挥想象,造出奇妙的动画效果。
[示例参考]
Drawable Animation
逐帧动画
原理:提供动画每个帧上的图片资源,顺序播放
[示例参考]
ClipDrawable 剪切动画
原理:提供一个背景图片,前景图片是一个ClipDrawable对象。通过线程操作ClipDrawable的剪切进度。
实例:
1 2 3 4 5 6
| <?xml version="1.0" encoding="utf-8"?> <clip xmlns:android="http://schemas.android.com/apk/res/android" android:clipOrientation="vertical" android:drawable="@drawable/loading_progress" android:gravity="bottom"> </clip>
|
1 2 3 4 5 6 7 8 9
| <ImageView android:id="@+id/iv" android:layout_width="wrap_content" android:layout_height="wrap_content" android:scaleType="centerInside" android:paddingTop="5dp" android:paddingLeft="5dp" android:background="@drawable/loading_bg" android:src="@drawable/clip_loading"/>
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| private Handler handler = new Handler() { @Override public void handleMessage(Message msg) { if (msg.what == MSG_WHAT) { mClipDrawable.setLevel(mProgress); } } }; ....... Runnable mRunnable = new Runnable() { @Override public void run() { isRunning = true; while (isRunning) { handler.sendEmptyMessage(MSG_WHAT); if (mProgress > MAX_PROGRESS) { mProgress = 0; } mProgress += 100; try { Thread.sleep(18); } catch (InterruptedException e) { e.printStackTrace(); } } } };
|