1. 程式人生 > >android 仿淘寶的載入重新整理效果

android 仿淘寶的載入重新整理效果

自定義view:

package com.taobao.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.LinearInterpolator;
import android.widget.ImageView;
import android.widget.RelativeLayout;

public class TBProgressBar extends RelativeLayout {
	
	public TBProgressBar(Context context) {
		super(context);
		initView(context);
	}
	
	public TBProgressBar(Context context, AttributeSet attrs) {
		super(context, attrs);
		initView(context);
	}

	private void initView(Context context) {
		
		ImageView round = new ImageView(context);
		round.setImageResource(R.drawable.loading);
		addView(round, new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
		
		LinearInterpolator li = new LinearInterpolator();
        Animation animation = AnimationUtils.loadAnimation(context, R.anim.tb);
        animation.setInterpolator(li);
        round.startAnimation(animation);
	}

}

相關的圖片:

load_bk.png


loading.png


anim檔案下面的tb.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >

    <rotate
        android:duration="800"
        android:fromDegrees="0.0"
        android:pivotX="50.0%"
        android:pivotY="50.0%"
        android:repeatCount="-1"
        android:toDegrees="+360.0" />

</set>

程式碼下載:

其他知識:

步驟:

  • 用任何圖片編輯器編輯一張ProgressBar需要的圖片
  • 用這張圖片建立一個animation drawable
<?xml version="1.0" encoding="utf-8"?>
<animated-rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/image_for_rotation"
android:pivotX="50%"
android:pivotY="50%" />

   @drawable/image_for_rotation
 就是那張做好的圖片
給ProgressBar widget設定android:indeterminateDrawable
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center">
<ProgressBar
android:indeterminateDrawable="@drawable/my_progress_indeterminate"
android:layout_height="100dp" android:layout_width="100dp"/>
</LinearLayout>
It is very easy! 這裡 you can download Sample project with custom Android ProgressBar.
轉自: How to make custom indeterminate ProgressBar in Android or how to change ProgressBar style or color