WEB开发网
开发学院手机开发Android 开发 Android 自定义 UI 组件 阅读

Android 自定义 UI 组件

 2010-03-04 04:00:00 来源:WEB开发网   
核心提示://加载表盘资源if (mDial == null) {mDial = r.getDrawable(com.android.internal.R.drawable.clock_dial);}//加载时针图片资源mHourHand = a.getDrawable(com.android.internal.R.stylea
//加载表盘资源

if (mDial == null) {

mDial = r.getDrawable(com.android.internal.R.drawable.clock_dial);

}

//加载时针图片资源

mHourHand = a.getDrawable(com.android.internal.R.styleable.AnalogClock_hand_hour);

if (mHourHand == null) {

mHourHand = r.getDrawable(com.android.internal.R.drawable.clock_hand_hour);

}

//加载分针图片

mMinuteHand = a.getDrawable(com.android.internal.R.styleable.AnalogClock_hand_minute);

if (mMinuteHand == null) {

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;

//注册一个消息过滤器,获取时间改变、时区改变的action

IntentFilter filter = new IntentFilter();

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);

上一页  1 2 3 4  下一页

Tags:Android 定义 UI

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