动画

作者: 古拉啦啦 | 来源:发表于2019-09-26 19:16 被阅读0次

    动画:
    帧动画:关键帧动画 FrameAnimation :是由多张图片快速切换形成动画

    • 配置动画:
    • 1.xml :动画是固定的
    • drawable 里面创建动画的xml文件
    • 2.代码:动画是不固定的

    xml配置动画的步骤:

    1.在res-》drawable下面创建一个xml文件
    把selector改为animation-list

    2.一个item对应一张图片(一帧图片),drawabl图片、duration:这张图片在播放中的播放时间,有几张图片就有几个item
    3.在xml文件里面增加一个ImagView,属性background中是由第一步中胚子的文件
    4.在Activitty 里面启动动画的三个步骤

    @Override
    public boolean onTouchEvent(MotionEvent event) {
    if(event.getAction() == MotionEvent.ACTION_DOWN){
       //1,获取动画的控件
        ImageView iv = findViewById( R.id.ab_adm);
        //2.通过控件获取动画
      
     AnimationDrawable anim= (AnimationDrawable) iv.getDrawable();
        //3.启动动画
        anim.start();
    }
    return true;
     }
    

    使用代码配置文件的步骤如下:

    1.在xml里面设置值限制一张图片
    2.在Activity里面写代码配置

    //1,创建一个动画资源
    
    AnimationDrawable anim = new AnimationDrawable();
    int [] resID={R.drawable.campfire01,R.drawable.campfire02,R.drawable.campfire03,R.drawable.campfire04,R.drawable.campfire05,R.drawable.campfire06,R.drawable.campfire07,R.drawable.campfire08,R.drawable.campfire09,R.drawable.campfire10,R.drawable.campfire11,R.drawable.campfire12,R.drawable.campfire13,R.drawable.campfire14,R.drawable.campfire15,R.drawable.campfire16,R.drawable.campfire17};
    //2,添加每一帧的动画
    
       for(int id:resID){
        anim.addFrame(getResources().getDrawable(id,null),100);
      }
    //anim.addFrame( getResources().getDrawable (R.drawable.campfire01,null),100);
    //3,使用动画资源
    
       ImageView iv = findViewById(R.id.ab_adm);
    iv.setImageDrawable(anim);
    //4.启动动画
    
     anim.start();
     }
    

    1.创建动画资源

     AnimationDrawable anim = new AnimationDrawable();
    

    2.增加每一帧动画

    for(int id:resID){
        anim.addFrame(getResources().getDrawable(id,null),100);
    }
    

    3.使用动画资源

    ImageView iv = findViewById(R.id.ab_adm);
    iv.setImageDrawable(anim);
    

    4.启动动画

    anim.start();

    相关文章

      网友评论

          本文标题:动画

          本文链接:https://www.haomeiwen.com/subject/mfzuyctx.html