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萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章