高仿凤凰新闻的加载效果

高仿凤凰新闻的加载效果

 

介绍:
模仿凤凰新闻的加载。两个圆球旋转缩放。使用Animator属性动画。
本例子主要来自:http://www.itlanbao.com/code/20151208/10000/100680.html,效果实现主要由new AnimatorSet()然后通过几个动画ObjectAnimator

 

代码实现:

public class Loading  {
	
	private Context context ;
	private ImageView big;
	private ImageView small;
	private View view;
	public  Loading(Context context) {
		this.context = context;
	}
	
	public View initConfig(){
		DisplayMetrics dm = new DisplayMetrics();
		WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
		manager.getDefaultDisplay().getMetrics(dm);
		view = View.inflate(context, R.layout.loadview, null);
		big = (ImageView) view.findViewById(R.id.big);
		small = (ImageView) view.findViewById(R.id.small);
		LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
		params.addRule(RelativeLayout.CENTER_VERTICAL);
		params.leftMargin = dm.widthPixels /2 - 25; 
		big.setLayoutParams(params);
		LayoutParams params2 = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
		params2.addRule(RelativeLayout.CENTER_VERTICAL);
		params2.leftMargin = dm.widthPixels /2 + 25; 
		small.setLayoutParams(params2);
		startAnimation();
		return view;
	}
	
	
	private void startAnimation(){
		AnimatorSet set = new AnimatorSet();
		ObjectAnimator animator = ObjectAnimator.ofFloat(big, "alpha", 0.2f, 1f , 0.2f);
		ObjectAnimator animator2 = ObjectAnimator.ofFloat(small, "alpha", 1f, 0.2f, 1f);
		ObjectAnimator animator3 = ObjectAnimator.ofFloat(view, "rotation", 0, 359);
		ObjectAnimator animator4 = ObjectAnimator.ofFloat(big, "scaleX", 0.2f, 1.4f,0.2f);
		ObjectAnimator animator5 = ObjectAnimator.ofFloat(small, "scaleX", 1.4f, 0.2f,1.4f);
		ObjectAnimator animator6 = ObjectAnimator.ofFloat(big, "scaleY", 0.2f, 1.4f,0.2f);
		ObjectAnimator animator7 = ObjectAnimator.ofFloat(small, "scaleY", 1.4f, 0.2f,1.4f);
		animator.setRepeatCount(Integer.MAX_VALUE);
		animator2.setRepeatCount(Integer.MAX_VALUE);
		animator3.setRepeatCount(Integer.MAX_VALUE);
		animator4.setRepeatCount(Integer.MAX_VALUE);
		animator5.setRepeatCount(Integer.MAX_VALUE);
		animator6.setRepeatCount(Integer.MAX_VALUE);
		animator7.setRepeatCount(Integer.MAX_VALUE);
		animator3.setDuration(10000);
		animator.setDuration(2000);
		animator2.setDuration(2000);
		animator4.setDuration(2000);
		animator5.setDuration(2000);
		animator6.setDuration(2000);
		animator7.setDuration(2000);
		set.setInterpolator(new LinearInterpolator());//不停顿  
		set.play(animator).with(animator2).with(animator3).with(animator4).with(animator5).with(animator6).with(animator7);
		set.start();
		
	}
	
}


//动画使用

Loading loading = new Loading(MainActivity.this);
		setContentView(loading.initConfig());

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值