android之animation-list+图片实现的粘稠的加载动画效果

Tween动画详解:http://blog.csdn.net/feng88724/article/details/6318430

用animation-list+图片实现的粘稠的加载动画效果:

一:progressbar的动画加载

AnimationDrawable animation = new AnimationDrawable();
		    		
		    		for (int i = 1; i < 61; i++) {
		    	
		    			animation.addFrame(Drawable.createFromPath(path+"/lmb_jump_"+i+".png"), 50);
		    		}
		    		
		    		animation.setOneShot(false);
		    		
		    		progressBar.setIndeterminateDrawable(animation);
		    		animation.start();


举例二:

package com.example.loadingview;

import android.content.Context;
import android.graphics.drawable.AnimationDrawable;
import android.util.AttributeSet;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;

public class LoadingView extends FrameLayout {

	private Context mContext;
	private ImageView ivLoading;
	private AnimationDrawable loadingAniDrawable;

	public LoadingView(Context context) {
		super(context);
		init(context);
	}

	public LoadingView(Context context, AttributeSet attrs) {
		super(context, attrs);
		init(context);
	}

	public LoadingView(Context context, AttributeSet attrs, int defStyleAttr) {
		super(context, attrs, defStyleAttr);
		init(context);
	}

	private void init(Context context) {
		mContext = context;
		View view = View.inflate(mContext, R.layout.loading_animation_layout, this);
		ivLoading = (ImageView) view.findViewById(R.id.iv_loading);
		/**
		 * 这里设置的是setBackgroundResource,那么你获取的时候通过getBackground
		 */
		// ivLoading.setBackgroundResource(R.anim.loading_animation);
		// loadingAniDrawable = (AnimationDrawable) ivLoading.getBackground();
		/**
		 * 这里设置的是setImageResource,那么你获取的时候通过getDrawable
		 */
		ivLoading.setImageResource(R.anim.loading_animation);
		loadingAniDrawable = (AnimationDrawable) ivLoading.getDrawable();
		if (View.GONE == getVisibility()) {
			loadingAniDrawable.stop();
		}
	}

	@Override
	public void setVisibility(int visibility) {
		super.setVisibility(visibility);
		if (View.GONE == visibility) {// 不可见时不执行动画
			stop();
		} else {// 可见时执行动画
			start();
		}
	}

	public void stop() {
		if (loadingAniDrawable.isRunning()) {
			loadingAniDrawable.stop();
		}
	}

	public void start() {
		if (!loadingAniDrawable.isRunning()) {
			loadingAniDrawable.start();
		}
	}
}


<RelativeLayout 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" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:gravity="center"
        android:orientation="vertical" >

        <ImageView
            android:id="@+id/iv_loading"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/lmb_jump_1" />

        <TextView
            android:id="@+id/tv_click_loading"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="努力加载中" />
    </LinearLayout>

</RelativeLayout>


此动画集合:animation-list的xml,可放在anim或者drawable目录下均可

<?xml version="1.0" encoding="UTF-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
    android:oneshot="false" >

    <!-- oneshot:true只显示一次,false:无限循环 -->
    <item
        android:drawable="@drawable/jump_1"
        android:duration="50"/>
    <item
        android:drawable="@drawable/jump_1"
        android:duration="50"/>
    <item
        android:drawable="@drawable/jump_2"
        android:duration="50"/>
    <item
        android:drawable="@drawable/jump_3"
        android:duration="50"/>
    <item
        android:drawable="@drawable/jump_4"
        android:duration="50"/>
   

</animation-list>




demo:http://download.csdn.net/detail/zhongwn/9425952

发布了68 篇原创文章 · 获赞 38 · 访问量 25万+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章