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>


代码下载:

http://download.csdn.net/detail/jdsjlzx/4402531




其他知识:


步骤:
  • 用任何图片编辑器编辑一张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

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值