自定义View仿魅族手机加速(手机管家)效果

转载请注明出处:http://blog.csdn.net/MAGIC_JSS/article/details/52245844;
看着魅族手机管家上的手机加速效果不错,决定自己实现之。希望自己加深对自定义View的理解和使用,也希望帮助需要类似效果的朋友。

先上效果:
这里写图片描述

由于是模拟器上运行的效果不是很好,真机上运行会好很多。

1、继承View

废话少说,直接上码;

/**
 * Created by magic on 2016年8月11日.仿魅族手机加速(手机管家)的效果
 */
@SuppressLint({
    "DrawAllocation", "Recycle" })
public class MyDataResidueView extends View {
   

	private Paint paint, paintText;
	private float arcWidth;
	private float width, height;
	// 中间数字描述
	private double numberDesc = 99;
	// 中间的底部描述
	private String desc = "内存剩余";
	// 进度默认为全部
	private int progress = 270;
	// 数值格式化
	private DecimalFormat df;
	// 百分比文字大小
	private int numberDescSize = 80;
	// 底部描述文字大小
	private int descSize = 40;
	// 边框宽度大小
	private int strokeWidth = 5;

	private int color;
	private int laterColor;
	private int textColor;

	private float paddingLeft, paddingTop, paddingRight, paddingBottom;
	private float offsetTop, offsetLeft;

	public MyDataResidueView(Context context) {
   
		super(context);
		init();
	}

	public MyDataResidueView(Context context, AttributeSet attrs) {
   
		super(context, attrs);
		getCustomAttribute(context, attrs);
		init();
	}

	public MyDataResidueView(Context context, AttributeSet attrs,
			int defStyleAttr) {
   
		super(context, attrs, defStyleAttr);
		getCustomAttribute(context, attrs);
		init();
	}

	/**
	 * 获取自定义属性
	 * 
	 * @param context
	 * @param attrs
	 */
	private void getCustomAttribute(Context context, AttributeSet attrs) {
   
		TypedArray array = context.obtainStyledAttributes(attrs,
				R.styleable.MyDataResidueView);
		desc = array
				.getString(styleable.MyDataResidueView_MyDataResidueView_desc);
		if (desc == null)desc = "内存剩余";
		color = array.getColor(
				styleable.MyDataResidueView_MyDataResidueView_color, context
						.getResources().getColor
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值