帧动画

来源:互联网 发布:特拉亨伯格数学计算法 编辑:程序博客网 时间:2024/06/13 22:19

   前面讲了三大动画的视图动画,现在就来简单介绍一下帧动画。

   现在先来看一下效果:

            

   一.使用xml布局的形式

   1.在drawable目录下新建一个xml

<?xml version="1.0" encoding="utf-8"?><animation-list xmlns:android="http://schemas.android.com/apk/res/android">    <item        android:drawable="@drawable/icon1"        android:duration="300"></item>    <item        android:drawable="@drawable/icon2"        android:duration="300"></item>    <item        android:drawable="@drawable/icon3"        android:duration="300"></item>    <item        android:drawable="@drawable/icon4"        android:duration="300"></item>    <item        android:drawable="@drawable/icon5"        android:duration="300"></item>    <item        android:drawable="@drawable/icon6"        android:duration="300"></item></animation-list>
   2.布局xml

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:orientation="vertical" android:layout_width="match_parent"    android:layout_height="match_parent">    <ImageView        android:id="@+id/main3_image"        android:src="@drawable/icon1"        android:layout_gravity="center"        android:layout_width="wrap_content"        android:layout_height="wrap_content" /></LinearLayout>
   3.Java代码

public class Main3Activity extends AppCompatActivity{    private ImageView image;    @Override    protected void onCreate(@Nullable Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main3);        initView();    }    private void initView() {        image= (ImageView) findViewById(R.id.main3_image);        image.setImageResource(R.drawable.my_frame_animation);        AnimationDrawable animationDrawable= (AnimationDrawable) image.getDrawable();        animationDrawable.start();    }}
   二.使用代码的形式

public class Main3Activity extends AppCompatActivity{    private ImageView image;    @Override    protected void onCreate(@Nullable Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main3);        initView();    }    private void initView() {        AnimationDrawable animationDrawable=new AnimationDrawable();        Drawable drawable=getResources().getDrawable(R.drawable.icon1);        Drawable drawable2=getResources().getDrawable(R.drawable.icon2);        Drawable drawable3=getResources().getDrawable(R.drawable.icon3);        Drawable drawable4=getResources().getDrawable(R.drawable.icon4);        Drawable drawable5=getResources().getDrawable(R.drawable.icon5);        Drawable drawable6=getResources().getDrawable(R.drawable.icon6);        //添加图片        animationDrawable.addFrame(drawable,300);        animationDrawable.addFrame(drawable2,300);        animationDrawable.addFrame(drawable3,300);        animationDrawable.addFrame(drawable4,300);        animationDrawable.addFrame(drawable5,300);        animationDrawable.addFrame(drawable6,300);        animationDrawable.setOneShot(false);        image.setImageDrawable(animationDrawable);        animationDrawable.start();    }}



  

0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 孕早期肚子紧绷怎么办 怀孕2个月同房了怎么办 怀孕前三月同房了怎么办 人流前三天同房了怎么办 人流后三天同房了怎么办 吃避孕药后月经量少怎么办 排卵日同房不想怀孕怎么办 排卵日同房没有怀孕怎么办 想怀孕想生儿子怎么办 到期大姨妈不来怎么办 怕怀孕月经不来怎么办 宫颈环扎后宫缩怎么办 来例假刺激外阴高潮了怎么办 客人消费完说没钱怎么办? 孕13周血糖偏高怎么办 餐后血糖高14点怎么办 餐后血糖20多怎么办 空腹血糖6.6饭后9.2怎么办 键盘shift键失效了怎么办 灵异附身夫妻不合怎么办 鞋子买大了半码怎么办 鞋子买小了半码怎么办 黑布鞋鞋面白了怎么办 黑布鞋不黑了怎么办 黑布鞋退白了怎么办 老北京布鞋款式太少怎么办 老人输液抽搐后昏迷怎么办 头七家里有狗怎么办 股票退市股民的钱怎么办 美国股票退市股民怎么办 百度云字幕和视频不同步怎么办 百度云加载字幕有延迟怎么办 很难适应新环境怎么办 蜘蛛丝碰到嘴唇上起包有毒怎么办? 电瓶车在路上爆胎了怎么办 嘴被虫子咬肿了怎么办 高铁管家购票失败怎么办 高铁车厢空调冷怎么办 高铁票过了时间怎么办 网购火车票丢了怎么办 改签没有票了怎么办