DevStore首页 > DEV资源 > 源码下载 > 源码详情

Android图表绘制(柱状图、圆形图、折线图)

 
紫豪 | 2014-10-06 10:42    浏览量(8790)    评论(19)    收藏(20)
功能分类:特效 支持平台:Android 运行环境:Eclipse
开发语言:Java 开发工具:Eclipse 源码大小:993.86KB
下载源码 1570 人下载

源码简介

利用自定义View层实现柱状图、圆形图、折线图的图表绘制,可以运用在一些评分统计类的App功能中。

源码截图

  • 整体效果
  • 下方折线图移动效果
DevStore所有源码来自用户上传分享,版权问题及牵扯到商业纠纷均与DevStore无关。

源码片段

public class HomeArc extends View { 

	private Paint paint_black, paint_white;
	private RectF rectf;
	private float tb;
	private int blackColor = 0x70000000; // 底黑色
	private int whiteColor = 0xddffffff; // 白色
	private int score;
	private float arc_y = 0f;
	private int score_text;

	public HomeArc(Context context, int score) {
		super(context);
		init(score);
	}

	public void init(int score) {
		this.score = score;
		Resources res = getResources();
		tb = res.getDimension(R.dimen.historyscore_tb);

		paint_black = new Paint();
		paint_black.setAntiAlias(true);
		paint_black.setColor(blackColor);
		paint_black.setStrokeWidth(tb * 0.2f);
		paint_black.setStyle(Style.STROKE);

		paint_white = new Paint();
		paint_white.setAntiAlias(true);
		paint_white.setColor(whiteColor);
		paint_white.setTextSize(tb*6.0f);
		paint_white.setStrokeWidth(tb * 0.2f);
		paint_white.setTextAlign(Align.CENTER);
		paint_white.setStyle(Style.STROKE);

		rectf = new RectF();
		rectf.set(tb * 0.5f, tb * 0.5f, tb * 18.5f, tb * 18.5f);

		setLayoutParams(new LayoutParams((int) (tb * 19.5f), (int) (tb * 19.5f)));

		this.getViewTreeObserver().addOnPreDrawListener(
				new OnPreDrawListener() {
					public boolean onPreDraw() {
						new thread();
						getViewTreeObserver().removeOnPreDrawListener(this);
						return false;
					}
				});
	}

	protected void onDraw(Canvas c) {
		super.onDraw(c);
		c.drawArc(rectf, -90, 360, false, paint_black);
		c.drawArc(rectf, -90, arc_y, false, paint_white);
		c.drawText("" + score_text, tb * 9.7f, tb * 11.0f, paint_white);
	}

	class thread implements Runnable {
		private Thread thread;
		private int statek;
		int count;

		public thread() {
			thread = new Thread(this);
			thread.start();
		}

		public void run() {
			while (true) {
				switch (statek) {
				case 0:
					try {
						Thread.sleep(200);
						statek = 1;
					} catch (InterruptedException e) {
					}
					break;
				case 1:
					try {
						Thread.sleep(15);
						arc_y += 3.6f;
						score_text++;
						count++;
						postInvalidate();
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
					break;
				}
				if (count >= score)
					break;
			}
		}
	}

}
  •   赞(2) 赞 +1 赞(2) 已赞
  •   收藏(20) 收藏 +1 已收藏 取消
  •   下载(1570)
评论(19)
xtfgq

xtfgq 2016-06-22 21:29:22

挺好的,不错
回复(0) 赞(0) 赞(1)
lwq503574209

lwq503574209 2015-08-26 09:26:30

挺好看的,谢谢
回复(0) 赞(0) 赞(1)
yajiu

yajiu 2015-08-13 14:52:42

挺好看的,谢谢
回复(0) 赞(0) 赞(1)
jack_chentao

jack_chentao 2015-06-25 14:27:45

不懂得地方太多了
回复(0) 赞(0) 赞(1)
t256478

t256478 2015-03-23 22:26:34

非常不错,学习了
回复(0) 赞(0) 赞(1)
  • 推荐
  • 审核
  • 收录
  • 获取活力值

源码上传作者

  • 138 能力值
  • 58 源码
  • 10 评测
  • 0 资料

热门源码