个性进度条--------菊花加载----Android 播放动画
public class MainActivity extends Activity {
private Movie gif;
private long gifStart;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(new CustomGifView(this));
}
//使用android 提供的Movie类进行动画的播放,自定义view
class CustomGifView extends View {
public CustomGifView(Context context) {
super(context);
gif = Movie.decodeStream(getResources().openRawResource(
R.drawable.progress5));
}
public void onDraw(Canvas canvas) {
long now = android.os.SystemClock.uptimeMillis();
if (gifStart == 0) {
gifStart = now;
}
if (gif != null) {
int dur = gif.duration();
if (dur == 0) {
dur = 1000;
}
int relTime = (int) ((now - gifStart) % dur);
gif.setTime(relTime);
gif.draw(canvas,160, 300);
invalidate();
}
}
}
}
源码地址
更多相关文章
- android 使用动画 Button移动后不响应点击事件的解决办法
- Android Animation Frame动画
- Android中帧动画实现
- android定制化开关机动画、铃音
- Android转场动画和共享元素动画兼容5.0以下版本的实现
- Android实用视图动画及工具系列之四:多状态CheckBox,可设置大小尺
- Android:通过ValueAnimator动画改变控件长宽失效的问题解决
- Android中重复执行动画bug