WEB开发网
开发学院手机开发Android 开发 Android 自定义 View 实例 AnalogClock 源码 阅读

Android 自定义 View 实例 AnalogClock 源码

 2010-02-22 16:09:00 来源:WEB开发网   
核心提示:mMinuteHand = r.getDrawable(com.android.internal.R.drawable.clock_hand_minute);}mCalendar = new Time(); //获取当前系统时间mDialWidth = mDial.getIntrinsicWidth(); //获取表盘

mMinuteHand = r.getDrawable(com.android.internal.R.drawable.clock_hand_minute);

}

mCalendar = new Time(); //获取当前系统时间

mDialWidth = mDial.getIntrinsicWidth(); //获取表盘图片的宽度

mDialHeight = mDial.getIntrinsicHeight(); //高度,同上

}

@Override

protected void onAttachedToWindow() {

super.onAttachedToWindow();

if (!mAttached) {

mAttached = true;

IntentFilter filter = new IntentFilter(); //注册一个消息过滤器,获取时间改变、时区改变的action

filter.addAction(Intent.ACTION_TIME_TICK);

filter.addAction(Intent.ACTION_TIME_CHANGED);

filter.addAction(Intent.ACTION_TIMEZONE_CHANGED);

getContext().registerReceiver(mIntentReceiver, filter, null, mHandler);

}

mCalendar = new Time();

onTimeChanged();

}

@Override

protected void onDetachedFromWindow() {

super.onDetachedFromWindow();

if (mAttached) {

getContext().unregisterReceiver(mIntentReceiver); //反注册消息过滤器

mAttached = false;

}

}

@Override

protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {

int widthMode = MeasureSpec.getMode(widthMeasureSpec);

int widthSize = MeasureSpec.getSize(widthMeasureSpec);

int heightMode = MeasureSpec.getMode(heightMeasureSpec);

int heightSize = MeasureSpec.getSize(heightMeasureSpec);

float hScale = 1.0f;

float vScale = 1.0f;

if (widthMode != MeasureSpec.UNSPECIFIED && widthSize < mDialWidth) {

hScale = (float) widthSize / (float) mDialWidth;

}

if (heightMode != MeasureSpec.UNSPECIFIED && heightSize < mDialHeight) {

vScale = (float )heightSize / (float) mDialHeight;

上一页  1 2 3 4  下一页

Tags:Android 定义 View

编辑录入:coldstar [复制链接] [打 印]
赞助商链接