看到支付宝启动界面,很清新,比较绚,于是做了个简单界面,只是完成了动画效果,并集成到一个控件上去,使用起来非常方便,本人较懒,完成这些效果后,就没再走下去了
不多说,上代码
package com.example.test;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.app.Activity;
import android.content.Context;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.animation.LinearInterpolator;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;
public class CircleAnim extends FrameLayout {
ImageView iv_anim;
ImageView iv_anim2;
int width;
ObjectAnimator anim;
ObjectAnimator anim2;
LayoutParams params;
LayoutParams params2;
AnimatorSet animSet;
public CircleAnim(Context context) {
super(context);
// TODO Auto-generated constructor stub
init();
}
public CircleAnim(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
init();
}
public CircleAnim(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
// TODO Auto-generated constructor stub
init();
}
@Override
protected void onAttachedToWindow() {
// TODO Auto-generated method stub
super.onAttachedToWindow();
animSet.start();
}
@Override
protected void onDetachedFromWindow() {
// TODO Auto-generated method stub
super.onDetachedFromWindow();
animSet.cancel();
}
private void init() {
this.setBackgroundColor(0xFF00285c);
DisplayMetrics mDisplayMetrics = new DisplayMetrics();// 屏幕分辨率容器
if (!(getContext() instanceof Activity)) {
return;
}
((Activity) getContext()).getWindowManager().getDefaultDisplay()
.getMetrics(mDisplayMetrics);
int w = mDisplayMetrics.widthPixels;
int h = mDisplayMetrics.heightPixels;
width = w > h ? h : w;
iv_anim = new ImageView(getContext());
iv_anim.setScaleType(ScaleType.FIT_CENTER);
iv_anim.setImageResource(R.drawable.crile);
params = new LayoutParams(width, width);
params.gravity = Gravity.CENTER;
this.addView(iv_anim, params);
iv_anim2 = new ImageView(getContext());
iv_anim2.setScaleType(ScaleType.FIT_CENTER);
iv_anim2.setImageResource(R.drawable.crile);
params2 = new LayoutParams((int) (width * 2 / 3), (int) (width * 2 / 3));
params2.gravity = Gravity.CENTER;
this.addView(iv_anim2, params2);
LinearInterpolator polator = new LinearInterpolator();
anim = ObjectAnimator.ofFloat(iv_anim, "rotation", 0f, 360f);
anim.setInterpolator(polator);
anim.setDuration(5000);
anim.setRepeatCount(-1);
LinearInterpolator polator2 = new LinearInterpolator();
anim2 = ObjectAnimator.ofFloat(iv_anim2, "rotation", 360f, 0f);
anim2.setInterpolator(polator2);
anim2.setDuration(5000);
anim2.setRepeatCount(-1);
animSet = new AnimatorSet();
animSet.play(anim).with(anim2);
}
}
以上代码是一个简单的View,继承FrameLayout,然后在里面加了两个ImageView,每个ImageView添加了一个动画,动画就是一个简单的圆周动画,并让他匀速转动,无限转下去,需要注意的是,如果不加LinearInterpolator 的放,默认动画效果会是先慢再快再慢的,整个代码非常简单,使用起来更简单:
package com.example.test;
import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
super.onCreate(savedInstanceState);
setContentView(new CircleAnim(this));
// setContentView(R.layout.main);
}
}
里面有张动画图片没有,可以到项目下载地址去下载:
点击下载源码