Android 使用几张图片制作成动画

AnimationDrawable-帧动画

帧动画的实现还是比较简单的,使用场景就是在一些需要有动态变化的图标时会用到。

首先需要在drawable下面添加location_loading.xml文件,主要是图片的轮播。

<animation-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:duration="350" android:drawable="@drawable/cam_dual_effect_acquiring_gps_1_icn" />
    <item android:duration="350" android:drawable="@drawable/cam_dual_effect_acquiring_gps_2_icn" />
    <item android:duration="350" android:drawable="@drawable/cam_dual_effect_acquiring_gps_3_icn" />
</animation-list>

我们可以通过两种方法引入这个轮播图片,一个是ImageView的src标签。另一个是progressbar。我们介绍一下progressbar

     <ProgressBar
      android:id="@+id/location_progressbar"
      android:layout_width="20dp"
      android:layout_height="20dp"
      android:indeterminate="false"
      android:indeterminateDrawable="@drawable/location_loading" />

对于使用imageView显示的方法

 public void SearchedLocIcon() {
        locimg.setImageResource(R.drawable.location_loading_done);
        AnimationDrawable anim = (AnimationDrawable) locimg.getDrawable();
        anim.start();
    }

 

思路还是很简单的,这个是博主要做的一个相机上的功能的demo。详细代码在下面github上。

public class MainActivity extends AppCompatActivity implements LocationIconCallback.Callback{

    private static final String TAG = "MainActivity";
    public ImageView locimg;
    public boolean status = false;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        locimg = (ImageView) findViewById(R.id.loc_status_icon);
        LocationIconCallback.setCallback(this);
    }

    //点击开始动画
    public void onTouchCall(View v) {
        if (status == false){
            LocationIconCallback.startLocSeachIcon();
            status = true;
        } else {
            LocationIconCallback.SearchedLocIcon();
            status = false;
        }
    }

    @Override
    public void startLocSeachIcon() {
         locimg.setImageResource(R.drawable.location_loading);
         AnimationDrawable anim = (AnimationDrawable) locimg.getDrawable();
         anim.start();
    }

    @Override
    public void SearchedLocIcon() {
        locimg.setImageResource(R.drawable.location_loading_done);
        AnimationDrawable anim = (AnimationDrawable) locimg.getDrawable();
        anim.start();
    }

    @Override
    public void stopLocIcon() {

    }

}

 

/**
 * Created by xiangzaixiansheng on 19-7-2.
 */

public class LocationIconCallback {
    private static Callback mCallback;

    public interface Callback {
        //搜索中动画
        void startLocSeachIcon();
        //搜索到动画
        void SearchedLocIcon();
        //关闭动画
        void stopLocIcon();
    }

    public static void startLocSeachIcon(){
        mCallback.startLocSeachIcon();
    }

    public static void SearchedLocIcon() {
        mCallback.SearchedLocIcon();
    }

    public static void stopLocIcon(){
        mCallback.stopLocIcon();

    }

    public static void setCallback(Callback Callback) {
        mCallback = Callback;
    }

}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值