资源简介
android模拟时钟控件 android studio
代码片段和文件信息
package com.example.xiaoluo.myapplication;
import android.annotation.TargetApi;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Build;
import android.util.AttributeSet;
import android.view.View;
import java.util.Calendar;
/**
* Created by xiaoluo on 2016/1/11.
*/
public class TimerView extends View {
private int mWidthmHeight;
public TimerView(Context context){
super(context);
}
public TimerView(Context contextAttributeSet attrs){
super(contextattrs);
}
public TimerView(Context context AttributeSet attrs int defstyleAttr) {
super(context attrs defstyleAttr);
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
protected void onDraw(Canvas canvas) {
//设置画布背景
canvas.drawColor(Color.GRAY);
//获取屏幕宽度
mWidth=getMeasuredWidth();
//获取屏幕高度
mHeight=getMeasuredHeight();
//获取系统时间
//Calendar里面月份的值是从0~11,对应1~12
//星期几是从星期天开始算的
Calendar calendar=Calendar.getInstance();
int year=calendar.get(Calendar.YEAR);
int month=calendar.get(Calendar.MONTH);
int day=calendar.get(Calendar.DAY_OF_MONTH);
int week=calendar.get(Calendar.DAY_OF_WEEK);
String sYearsMonthsDaysWeek;
sYear=String.valueOf(year);
sMonth=String.valueOf(month+1);
sDay=String.valueOf(day);
sWeek=String.valueOf(week);
if (week==1){
sWeek=“日“;
}else if(week==2){
sWeek=“一“;
}else if(week==3){
sWeek=“二“;
}else if(week==4){
sWeek=“三“;
}else if(week==5){
sWeek=“四“;
}else if(week==6){
sWeek=“五“;
}else if(week==7){
sWeek=“六“;
}
int hour=calendar.get(Calendar.HOUR_OF_DAY);
if (hour>12){
hour=hour-12;
}
int minute=calendar.get(Calendar.MINUTE);
int second=calendar.get(Calendar.SECOND);
//显示时间
Paint paintTime=new Paint();
paintTime.setColor(Color.BLUE);
//要先设置画笔颜色后,设置透明度才有效果
paintTime.setAlpha(100);
paintTime.setStrokeWidth(25);
paintTime.setTextSize(50);
String mHour=String.valueOf(hour);
canvas.drawText(mHour mWidth / 2-80 mHeight / 2-130 paintTime);
canvas.drawText(“:“ mWidth / 2-20 mHeight / 2-130 paintTime);
String mMinute=String.valueOf(minute);
canvas.drawText(mMinute mWidth / 2 mHeight / 2-130 paintTime);
canvas.drawText(“:“ mWidth / 2+60 mHeight / 2-130 paintTime);
String mSecond=String.valueOf(second);
canvas.drawText(mSecondmWidth/2+80mHeight/2-130paintTime);
canvas.drawText(sYear+“.“+sMonth+“.“+sDay+“-----星期“+sWeekmWidth/2-200mHeight/2+180paintT
- 上一篇:JSP+servlet的后台管理系统
- 下一篇:12306.html
相关资源
- Java 简单的数字时钟
- Java 简单的模拟时钟
- Android 时钟模拟设计的应用(Android高
- java实现电子时钟(完整源代码)
- Java入门-数字时钟(16).zip
- Java 简单的电子时钟
- 自定义spinnner
- android自定义控件
- Android 外星人手机时钟(Android 常用控
- android 时钟app源码入门级
- android 自定义画笔时钟
- android 高仿优酷弹出菜单
- 时钟java源代码
- JAVA课程设计(论文) 时钟
- Adroid自定义数字键盘控件
- java模拟时钟
- java课程设计时钟日历含代码
- Java时钟程序(绘制了一个带时针 分针
- android 2d时钟
- Android自定义控件
- 自定义控件-颜色取色器
- Android高仿小米时钟
- android 日历app源码(附带时钟功能)
- android手机时钟、闹钟、计时器、秒表
- android 闹钟/秒表/倒计时
评论
共有 条评论