androidの高仿支付宝扫描动画效果

androidの高仿支付宝扫描动画效果
1. 扫描动画效果,效果如图所示
 
2. 通过效果图,可以看到最边缘的一个圆环,顺时针转动,内部出现辐射光圈。
  先看代码,创建一个Activity.
public class MainActivity extends Activity {
	private ImageView iv = null;
	private RadiationView rv = null;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		iv = (ImageView) findViewById(R.id.iv_rotate);//边缘圆环
		rv = (RadiationView) findViewById(R.id.rv);
		rv.setMinRadius(70);//辐射半径
		rv.startRadiate();//开始辐射
		Animation anim = AnimationUtils.loadAnimation(this,
				R.anim.rotate_circle_anim);
		iv.startAnimation(anim);//开始动画
	}
}
然后,是对应的xml 文件
<LinearLayout 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"
    android:gravity="center"
    tools:context=".MainActivity" >
    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:src="@drawable/homepage_disk_button_orange_normal" />
        <ImageView
            android:id="@+id/iv_rotate"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:src="@drawable/homepage_disk_orange_normal" />
        <com.kince.radiationview.RadiationView
            android:id="@+id/rv"
            android:layout_width="250dp"
            android:layout_height="250dp"
            android:layout_gravity="center" />
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:text="扫描"
            android:textColor="#ffffff"
            android:textSize="30sp" />
    </FrameLayout>
</LinearLayout>
public class RadiationView extends View {
	private Paint mPaint = new Paint();
	private int mColor = 0x3f990e;
	private int mAlpha = 60;
	private Handler mHandler = null;
	private static final int MESSAGE_DRAW = 0;
	private static final String TAG = "RadiationView";
	private int width;
	private int height;
	private int speed = 30;
	private int maxRadius = 100;
	private int centerX;
	private int centerY;
	private int minRadius = 70;
	private int radius = minRadius;
	private boolean isStarted = false;

	public RadiationView(Context context) {
		super(context);
		System.out.println("blueberry_RadiationView1");
		init();
	}
	public RadiationView(Context context, AttributeSet attrs) {
		super(context, attrs, 0);
		System.out.println("blueberry_RadiationView2");
		init();
	}

	public void startRadiate() {
		System.out.println("blueberry_startRadiate");
		isStarted = true;
		mHandler.sendEmptyMessage(MESSAGE_DRAW);
	}

	private void init() {
		System.out.println("blueberry_init");
		mPaint = new Paint();
		mPaint.setStrokeWidth(1);
		mPaint.setColor(mColor);
		mPaint.setAlpha(mAlpha);
		mHandler = new Handler() {
			public void handleMessage(android.os.Message msg) {
				if (msg.what == MESSAGE_DRAW) {
					invalidate();
					if (isStarted) {
					sendEmptyMessageDelayed(MESSAGE_DRAW, speed);
					}
				}
			}
		};
	}

	@Override
	protected void onLayout(boolean changed, int left, int top, int right,
			int bottom) {
		super.onLayout(changed, left, top, right, bottom);
		System.out.println("blueberry_onlayout");
		width = this.getWidth();
		height = this.getHeight();
		if (width <= 0 || height <= 0) {
			throw new RuntimeException("size illegal");
		}
		centerX = width / 2;
		centerY = height / 2;
		maxRadius = (width > height) ? height / 2 : width / 2;
		System.out.println("blueberry_maxRadius="+maxRadius);
		Log.i(TAG, "MAX" + maxRadius);
		if (maxRadius < 70) {
			throw new RuntimeException("size too small");
		}
	}

	@Override
	protected void onDraw(Canvas canvas) {
		System.out.println("blueberry_ondraw");
		mPaint.setColor(mColor);
		mPaint.setAlpha(mAlpha);
		if (radius <= 0) {
			return;
		}
		if (radius > maxRadius) {
			radius = minRadius;
		}
		canvas.save();
		canvas.drawCircle(centerX, centerY, radius, mPaint);
		canvas.restore();
		radius += 1;
	}

	@Override
	protected void onAttachedToWindow() {
		super.onAttachedToWindow();
		this.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
	}

	public void setColor(int color) {
		this.mColor = color;
	}

	public void setSpeed(int speed) {
		this.speed = speed;
	}

	public void setMinRadius(int radius) {
		this.minRadius = radius;
	}
}
根据xml布局,采用Framelayout,定义了一个 <com.kince.radiationview.RadiationView,
用来显示辐射半径。在MainActivity中,设置了辐射最小半径,然后启动,

3. 代码地址

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Android实用控件自定义逼真相机光圈View 作者:佚名 来源:吾爱源码 2016-08-12 14:46:40 0 最近手机界开始流行双摄像头,大光圈功能也应用而生。所谓大光圈功能就是能够对照片进行后期重新对焦,其实现的原理主要是对拍照期间获取的深度图片与对焦无穷远的图像通过算法来实现重新对焦的效果。 在某双摄手机的大光圈操作界面有个光圈的操作图标,能够模拟光圈调节时的真实效果,感觉还不错,于是想着实现该效果。现在把我的实现方法贡献给大家,万一你们公司也要做双摄手机呢?( ̄┰ ̄*) 首先,百度一下光圈图片,观察观察,就可以发现其关键在于计算不同的光圈值时各个光圈叶片的位置。为了计算简便,我以六个直边叶片的光圈效果为例来实现(其他形式,比如七个叶片,也就是位置计算稍微没那么方便;而一些圆弧的叶片,只要满足叶片两边的圆弧半径是一样的就行。为什么要圆弧半径一样呢?仔细观察就可以发现,相邻两叶片之间要相互滑动,而且要保持一样的契合距离,根据我曾今小学几何科打满分的经验可以判断出,等径的圆弧是不错滴,其他高级曲线能不能实现该效果,请问数学家( ̄┰ ̄*)!其他部分原理都是一样的)。 制作效果图: 先说明一下本自定义view的主要内容: 1.本效果的实现就是在光圈内六边形六个角上分别绘制六个光圈叶片 2.根据不同的光圈值计算出内六边形的大小,从而计算每个六边形的顶点的位置 3.设计叶片。也可以让美工MM提供,本方案是自己用代码画的。注意预留叶片之间的间隔距离以及每个叶片的角度为60° 4.定义颜色、间隔等自定义属性 5.上下滑动可以调节光圈大小 6.提供光圈值变动的监听接口

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值