admin管理员组

文章数量:1666598

转载请注明出处:http://blog.csdn/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

本文标签: 手机自定义管家魅族效果