android 动画--帧动画--仿美团加载中小人

1 把资源图片放到drawable中

2 在drawable中写动画的xml文件animation01

这里写图片描述

Animation01.xml
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
    android:oneshot="false"  //false为连续播放 true为只播放一次
    >
    <item android:drawable="@drawable/progress_loading_image_01" android:duration="100"></item>   //播放的时间
    <item android:drawable="@drawable/progress_loading_image_02" android:duration="100"></item>  
    <item android:drawable="@drawable/progress_loading_image_03" android:duration="100"></item>  
    <item android:drawable="@drawable/progress_loading_image_04" android:duration="100"></item>  
</animation-list>

3布局文件中

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
     >

    <Button
        android:id="@+id/but_animationStart"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="播放游游动画" />
    <Button
        android:id="@+id/but_animationEnd"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="停止游游动画" />

     <ImageView 
      android:id="@+id/image_animation"
      android:layout_width="100dp"
      android:layout_height="100dp"
      android:background="@drawable/animation01"/>
</LinearLayout>

4 代码中引入动画

public class MainActivity extends Activity {
    private AnimationDrawable animationDrawable;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.fragment_main);

        Button but_start=(Button) findViewById(R.id.but_animationStart);
        Button but_end=(Button) findViewById(R.id.but_animationEnd);
        final ImageView imageAnima=(ImageView) findViewById(R.id.image_animation);

        but_start.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                imageAnima.setImageResource(R.drawable.animation01);  
                animationDrawable = (AnimationDrawable) imageAnima.getDrawable();  
                animationDrawable.start();
                imageAnima.setBackgroundColor(android.graphics.Color.parseColor("#00ffffff"));

            }
        });

        but_end.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                animationDrawable = (AnimationDrawable) imageAnima.getDrawable();  
                animationDrawable.stop(); 

            }
        });
    }



}

这里写图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值