AnimationDrawable是实现Drawable animations的基本类。 推荐用XML文件的方法实现Drawable动画,不推荐在代码中实现。...animationDrawable = (AnimationDrawable)loadingImageView.getBackground(); loadingImageView.post...对象, 代码如下: rocketAnimation = (AnimationDrawable) rocketImage.getBackground(); start()方法不能在onCreate()...因为AnimationDrawable并未完全关联到Window, 在onCreate()方法中,View并未完成显示(同理,在此方法中测量某个View的宽高,常得到0值。...: android.graphic.drawable.AnimationDrawable //获得我们xml定义的AnimationDrawable animDrawable
imageView_2 = findViewById(R.id.image_2); AnimationDrawable animationDrawable1 = new AnimationDrawable...animationDrawable1.addFrame(getResources().getDrawable(R.drawable.iron_2 ),200); animationDrawable1...animationDrawable1.addFrame(getResources().getDrawable(R.drawable.iron_8 ),200); animationDrawable1....setOneShot(true); imageView_2.setImageDrawable(animationDrawable1); animationDrawable1...animationDrawable = (AnimationDrawable) imageView_1.getDrawable(); animationDrawable.start()
获取动画对象 animationDrawable = (AnimationDrawable) iv.getDrawable(); //...获取动画对象 animationDrawable = (AnimationDrawable) iv.getDrawable(); //...// 直接从drawable文件夹获取动画资源(图片) animationDrawable = new AnimationDrawable(); for (int...获取资源对象 iv.setImageDrawable(animationDrawable); // 2....停止动画 animationDrawable.stop(); } }); 4.
变回最初的状态 repeatCount:重复的次数(不包括第一次) startOffset:距离动画开始的时间 repeatMode:1表示重新开始,2表示从最后一个状态往回逆序播放 帧动画: 实现方法 1.实例AnimationDrawable...import android.annotation.SuppressLint; import android.app.Activity; import android.graphics.drawable.AnimationDrawable...rotateAnimation); scaleAnimation.setStartOffset(10000); set2.addAnimation(scaleAnimation); /** * 帧动画 */ //第一种 //AnimationDrawable...间接继承Drawable AnimationDrawable ad = new AnimationDrawable(); Drawable frame1 = getResources().getDrawable...ad1 = (AnimationDrawable) tv.getBackground(); ad1.start(); } @Override public void finish() { super.finish
animationDrawable; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate...= (AnimationDrawable) animationIV.getDrawable(); animationDrawable.start(); }...@Override public void onClick(View v) { // TODO Auto-generated method stub animationDrawable...= (AnimationDrawable) animationIV.getDrawable(); animationDrawable.stop(); }...= (AnimationDrawable) animationIV.getDrawable(); animationDrawable.start(); }
设置动画 animationDrawable = (AnimationDrawable) iv.getDrawable(); // 2....获取动画对象 animationDrawable.start(); // 3....设置动画 animationDrawable = (AnimationDrawable) iv.getDrawable(); // 2....获取动画对象 animationDrawable.stop(); // 3....(true); iv.setImageDrawable(animationDrawable); animationDrawable.stop
以imageview为载体可以在xml设置src和在类中用iamgeview.getDrawable获取AnimationDrawable,再调用start方法或者stop方法。 调用帧动画 写好xml文件我们就可以在类中通过以下方法来调用动画 mImageView.setImageResource(R.drawable.frame); AnimationDrawable...drawable = (AnimationDrawable) mImageView.getDrawable(); drawable.start(); ```# 帧动画 下面我们来说什么是帧动画。...以imageview为载体可以在xml设置src和在类中用iamgeview.getDrawable获取AnimationDrawable,再调用start方法或者stop方法。...drawable = (AnimationDrawable) mImageView.getDrawable(); drawable.start();
anim = (AnimationDrawable)getDrawable(); anim.start(); } /** * 带动画监听的播放 * @param resId *...anim = (AnimationDrawable)getDrawable(); anim.start(); if(listener !...AnimationDrawable frameAnimation = (AnimationDrawable) img.getBackground(); // Start the animation...AnimationDrawable frameAnimation = (AnimationDrawable) img.getBackground(); Drawable getDrawable(...anim = (AnimationDrawable)getDrawable();//得到一个AnimationDrawable对象 anim.start();//然后启动动画 }
//将帧动画的资源文件设置为imageview的背景 iv.setBackgroundResource(R.drawable.frameanimation); c:获得AnimationDrawable...对象 //获取AnimationDrawable对象 AnimationDrawable ad = (AnimationDrawable) iv.getBackground...//将帧动画的资源文件设置为imageview的背景 iv.setBackgroundResource(R.drawable.frameanimation); //获取AnimationDrawable...对象 AnimationDrawable ad = (AnimationDrawable) iv.getBackground(); //开始播放动画 ad.start
lastPosition); lastPosition = position; id_iv_voice.setBackgroundResource(R.drawable.animation_voice); animationDrawable...= (AnimationDrawable) id_iv_voice.getBackground(); if(MediaManager.isPlaying()){ stopAnimation(); MediaManager.pause...animationDrawable; if(obj.isSelect){ iv_voice.setBackgroundResource(R.drawable.animation_voice); animationDrawable...= (AnimationDrawable) iv_voice.getBackground(); if(MediaManager.isPlaying() && animationDrawable!...=null){ animationDrawable.start(); }else{ iv_voice.setBackgroundResource(R.drawable.voice_listen); animationDrawable.stop
实现原理: 准备3张不同角度的图片,通过AnimationDrawable帧动画进行播放即可 代码实现: 1、编写动画xml文件: <?...open_red_animation_drawable" / 注意是使用background来加载动画而不是src 3、代码中启动需要播放动画的控件 //ivOpen指的是需要播放动画的ImageView控件 AnimationDrawable...animationDrawable = (AnimationDrawable)ivOpen.getBackground(); animationDrawable.start();//启动动画 总结 以上所述是小编给大家介绍的
image.backgroundDrawable = resources.getDrawable(R.drawable.frame_drawable_test) // getBackground() 取得 AnimationDrawable...对象 val animDrawable : AnimationDrawable = image.background as AnimationDrawable // 启动动画 animDrawable.start...() // 作为 Resource image.imageResource = R.drawable.frame_drawable_test // getDrawable() 取得 AnimationDrawable...对象 val animDrawable2 : AnimationDrawable = image.drawable as AnimationDrawable animDrawable.stop() /.../ 停止动画 animDrawable2.start() 代码方式 val animDrawable = AnimationDrawable() animDrawable.isOneShot
com.example.exmgif.util.GifImage.GifFrame; import android.app.Activity; import android.graphics.drawable.AnimationDrawable...return getResources().getDrawable(id); } private void showFrameAnimation() { //帧动画需要把每帧图片加入AnimationDrawable...队列 AnimationDrawable animationList = new AnimationDrawable(); animationList.addFrame(getDraw(R.drawable.flow_p1...gifList = new AnimationDrawable(); for (int i=0; i<frameList.length; i++) { //BitmapDrawable用于把...》 3、NinePatchDrawable:详见《Android开发笔记(九)特别的.9图片》 4、TransitionDrawable:详见《Android开发笔记(十五)淡入淡出动画》 5、AnimationDrawable
Drawable子类之——InsetDrawable (嵌入) ClipDrawable Drawable子类之——ClipDrawable (裁剪图像) ScaleDrawable RotateDrawable AnimationDrawable...item android:drawable="@drawable/rocket_thrust3" android:duration="200" /> 我们可以看到,AnimationDrawable...我们可以通过编码来加载播放动画: // Load the ImageView that will host the animation and // set its background to our AnimationDrawable...AnimationDrawable frameAnimation = (AnimationDrawable) img.getBackground(); // Start the animation...frameAnimation.start(); 注意:AnimationDrawable. start()方法不能够在Activity的onCreate()方法中调用,因为AnimationDrawable
aniImageView.setImageResource(R.drawable.pull_end_imag_frame); AnimationDrawable...animationDrawable = (AnimationDrawable) aniImageView.getDrawable(); // 只执行一次动画...animationDrawable.setOneShot(true); animationDrawable.start...aniImageView.setImageResource(R.drawable.refreshing_image_frame); AnimationDrawable...animationDrawable = (AnimationDrawable) aniImageView.getDrawable(); animationDrawable.start
image = (ImageView) findViewById(R.id.iv_sound); image.setImageResource(R.drawable.sounds); AnimationDrawable...animationDrawable = (AnimationDrawable) image.getDrawable(); animationDrawable.start() 如有疑问请留言或者到本站社区交流讨论
帧动画最简单,通过顺序播放一系列的图像产生动画,有点类似动画片 以tomcat案例来讲解 1、首先准备好一组图片(网上找的现成的一组图片),然后定义一个AnimationDrawable,命名为ani.xml...android:layout_height="match_parent" android:background="@drawable/ani" /> 3、通过AnimationDrawable...R.layout.activity_main); ImageView imageView = (ImageView) findViewById(R.id.imageView1); final AnimationDrawable...background = (AnimationDrawable) imageView .getBackground(); imageView.setOnClickListener
item> 这样图片就一层层的叠起来了 动画调用 public class MainActivity extends Activity { private AnimationDrawable...findViewById(R.id.loading); loadingImg.setBackgroundResource(R.drawable.loading); loadingAnimation = (AnimationDrawable...super.onWindowFocusChanged(hasFocus); if (hasFocus) loadingAnimation.start(); } } 需要注意的是,不能在onCreate()方法中调用AnimationDrawable...的start()方法,因为此时AnimationDrawable还未真正加载到界面中。
. */ public class AnimImageViewLoader extends ImageView { private AnimationDrawable frameAnimation...super(context); init(); } /** * 初始化动画信息 */ private void init() { frameAnimation = (AnimationDrawable...} }); } /** * 开启动画显示 */ public void startAnimation() { frameAnimation = (AnimationDrawable
第二步: 将xml文件用和AnimationDrawable关联。(我们是xml实现也可以代码实现,demo中有此处省略。。。。)...AnimationDrawable mAnimationDrawable =(AnimationDrawable) getResources().getDrawable( R.drawable.anim_frame...然后初始化Imageview 在.setBackground(animationDrawable);即可。 完毕!
领取专属 10元无门槛券
手把手带您无忧上云