Android 幀動畫打造動態ImageView
實現
新建AnimatorImageView 繼承AppCompatImageView/ImageView
public class AnimatorImageView extends AppCompatImageView {
public AnimatorImageView(Context context) {
super(context);
}
public AnimatorImageView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public AnimatorImageView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
if (getVisibility() == VISIBLE) {
animator(true);
}
}
@Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
animator(false);
}
@Override
public void setVisibility(int visibility) {
super.setVisibility(visibility);
if (VISIBLE == visibility) {
animator(true);
} else {
animator(false);
}
}
/**
* 啟動或停止動畫
* @param start
* true為啟動動畫; false為停止動畫
*/
public void animator(boolean start) {
try {
AnimationDrawable animationDrawable = (AnimationDrawable) getDrawable();
if (animationDrawable == null) {
return;
}
animationDrawable.stop();
if (start) {
animationDrawable.start();
}
} catch (Exception e) {
Log.e("AnimatorImageView", e.getMessage());
}
}
}
呼叫
1、drawable中新建animation-list檔案practicing_animator.xml
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:duration="200" android:drawable="@mipmap/practicing1" />
<item android:duration="200" android:drawable="@mipmap/practicing2" />
<item android:duration="200" android:drawable="@mipmap/practicing3" />
<item android:duration="200" android:drawable="@mipmap/practicing4" />
</animation-list>
2、layout佈局檔案中呼叫(呼叫方式與ImageView相同)
<xxx.xxx.xxx.AnimatorImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/practicing_animator" />
相關文章
- android動態新增ImageView注意AndroidView
- Android 幀動畫使用Android動畫
- Android備忘錄《幀動畫》Android動畫
- Android開發之幀動畫Android動畫
- Android 動畫詳解:屬性動畫、View 動畫和幀動畫Android動畫View
- Android動畫效果之Frame Animation(逐幀動畫)Android動畫
- ImageView 動態設定大小View
- 動態建立ImageView檢視View
- View動畫、幀動畫View動畫
- Unity幀動畫Unity動畫
- Android佈局中動態新增ImageView並設定間隔AndroidView
- CSS技巧:逐幀動畫抖動解決方案CSS動畫
- CSS3動畫之逐幀動畫CSSS3動畫
- Android播放聊天語音訊息幀動畫問題Android音訊動畫
- iOS 關鍵幀動畫iOS動畫
- CSS3 animation逐幀動畫CSSS3動畫
- 一起動手實現一個js幀動畫庫JS動畫
- html5--6-55 動畫效果-關鍵幀動畫HTML動畫
- Android:ImageView控制元件AndroidView控制元件
- Android ImageView和TextView居中AndroidTextView
- 幀動畫記憶體OOM?不存在的!—— SurfaceView逐幀解析動畫記憶體OOMView
- css3實現逐幀動畫CSSS3動畫
- Web 動畫幀率(FPS)計算Web動畫
- 使用gif分幀工具分解gif動畫動畫
- css3 實現逐幀動畫CSSS3動畫
- Android優化幀動畫過程中的多執行緒模型思考Android優化動畫執行緒模型
- 使用ScrollView滾動事件打造動畫框架ScrollAnimationSherlockView事件動畫框架
- Android ImageView 清空背景圖片AndroidView
- android 中ImageView 無法居中AndroidView
- 動態的新增ImageView到LinearLayout中並居中顯示View
- android 滾動手勢動畫Android動畫
- Android 模仿微信啟動動畫Android動畫
- 深入理解CSS3 Animation 幀動畫CSSS3動畫
- SVG實現動態模糊動畫效果SVG動畫
- SVG 實現動態模糊動畫效果SVG動畫
- 用 PHP 動態建立 Flash 動畫 (轉)PHP動畫
- Android圖片底部居中的ImageViewAndroidView
- Android ImageView對齊方式設定AndroidView