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
版权声明:本文标题:自定义View仿魅族手机加速(手机管家)效果 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://www.elefans.com/xitong/1730065695a1221337.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论