一· 屏幕中坐標(biāo)系的認(rèn)知:
貼三張圖就明白清楚了秤掌,參考地址:
https://github.com/GcsSloop/AndroidNote/blob/master/CustomView/Base/%5B01%5DCoordinateSystem.md
二· 自定義view分類君珠,流程及一些重要函數(shù):
三· 自定義一個(gè)數(shù)字時(shí)鐘
public class MyClock extends TextView {
private final static String TAG = "DigitalClock";
private Calendar mCalendar;
private String mFormat = "yyyy-MM-dd HH:mm:ss E"; //根據(jù)不同的時(shí)間格式顯示不同
private Runnable mTicker;
private Handler mHandler;
private boolean mTickerStopped = false;
public MyClock(Context context) {
super(context);
initClock(context);
}
public MyClock(Context context, AttributeSet attrs) {
super(context, attrs);
initClock(context);
}
private void initClock(Context context) {
if (mCalendar == null) {
mCalendar = Calendar.getInstance();
}
}
@Override
protected void onAttachedToWindow() {
mTickerStopped = false;
super.onAttachedToWindow();
mHandler = new Handler();
mTicker = new Runnable() {
public void run() {
if (mTickerStopped)
return;
mCalendar.setTimeInMillis(System.currentTimeMillis());
setText(DateFormat.format(mFormat, mCalendar));
invalidate();
long now = SystemClock.uptimeMillis();
long next = now + (1000 - System.currentTimeMillis() % 1000);
mHandler.postAtTime(mTicker, next);
}
};
mTicker.run();
}
@Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
mTickerStopped = true;
}
}