- 生肖
- 虎
- 星座
- 狮子座
- 自我介绍
- 新年第一天据说有雨,全民齐赏日出的计划恐要泡汤。”宋仁宗拍着包拯的肩,“朕决定把你悬挂在城门上。”“但微臣额上的不是太阳是月亮啊!”“没事,挂久一点就会升级成太阳
- 性别
- 男
- 积分
- 368
- 积分
- 739
- 精华
- 0
- 阅读权限
- 150
- 注册时间
- 2012-4-28
- 最后登录
- 2016-9-20
- 帖子
- 247
- 自我介绍
- 新年第一天据说有雨,全民齐赏日出的计划恐要泡汤。”宋仁宗拍着包拯的肩,“朕决定把你悬挂在城门上。”“但微臣额上的不是太阳是月亮啊!”“没事,挂久一点就会升级成太阳
- 生肖
- 虎
- 星座
- 狮子座
- 性别
- 男
|
activity- package com.rogan.clock;
- import android.app.Activity;
- import android.os.Bundle;
- public class ClockActivity extends Activity {
- private ClockView clockView = null;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- clockView = new ClockView(this);
- setContentView(clockView);
- new Thread(new clockThread()).start();
- }
- /**
- * Clock refresh
- */
- class clockThread implements Runnable {
- @Override
- public void run() {
- while (!Thread.currentThread().interrupted()) {
- clockView.postInvalidate();
- try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
- Thread.currentThread().interrupt();
- }
- }
- }
- }
- }
复制代码 clockview- package com.rogan.clock;
- import android.content.Context;
- import android.graphics.Canvas;
- import android.graphics.Color;
- import android.graphics.Paint;
- import android.view.View;
- /**
- * Created by Administrator on 13-7-9.
- */
- public class ClockView extends View implements Runnable {
- int mcount = 0;
- private Paint mPaint = null;
- public ClockView(Context context) {
- super(context);
- mPaint = new Paint();
- new Thread(this).start();
- }
- @Override
- protected void onDraw(Canvas canvas) {
- super.onDraw(canvas);
- canvas.drawColor(Color.BLACK);
- mPaint.setAntiAlias(true);
- mPaint.setStrokeWidth(3);
- mPaint.setStyle(Paint.Style.STROKE);
- mPaint.setColor(Color.WHITE);
- canvas.drawCircle(200, 500, 200, mPaint);
- if (mcount < 60) {
- mcount++;
- } else {
- mcount = 0;
- }
- float x = (float)(200 + 200 * Math.sin((mcount * Math.PI)/30));
- float y = (float)(300 + 200*(1- Math.cos((mcount * Math.PI)/30)));
- switch (mcount) {
- case 0:case 60: {
- canvas.drawLine(200, 500, 200, 300, mPaint);
- }
- break;
- default: {
- canvas.drawLine(200.0f, 500.0f, x, y, mPaint);
- }
- }
- }
- @Override
- public void run() {
- }
- public static void main(String[] args) {
- System.out.println("sdf:x="+ (float)(200 + 200*1 * Math.sin(Math.PI/30))+"y="+(float)(300 + 200*(1-1 * Math.cos(Math.PI/30))) );
- }
- }
复制代码 |
|