45
R.drawable.split_left_1);
46
bg_off = BitmapFactory.decodeResource(getResources(),
47
R.drawable.split_right_1);
48
slip_btn = BitmapFactory.decodeResource(getResources(),
49
R.drawable.split_1);
50
51
btn_off_left = bg_off.getWidth() - slip_btn.getWidth();
52
53
setOnTouchListener(
this
);
//
设置监听器
,也可以直接复写 OnTouchEvent
54
}
55
56
@Override
57
protected
void
onDraw(Canvas canvas) {
//
绘图函数
58
super.onDraw(canvas);
59
60
Matrix matrix =
new
Matrix();
61
Paint paint =
new
Paint();
62
float
x;
63
64
if
(NowX < (bg_on.getWidth() /
2
)) {
//
滑动到前半段与后半段的背景不同
,在此做判
断
65
x = NowX - slip_btn.getWidth() /
2
;
66
canvas.drawBitmap(bg_off, matrix, paint);
//
画出关闭时的背景
67
}
else
{
68
x = bg_on.getWidth() - slip_btn.getWidth() /
2
;
69
canvas.drawBitmap(bg_on, matrix, paint);
//
画出打开时的背景
70
}
71
72
if
(OnSlip) {
//是否是在滑动状态,
73
if
(NowX >= bg_on.getWidth()) {
//
是否划出指定范围
,不能让游标跑到外头,必须做
这个判断
74
x = bg_on.getWidth() - slip_btn.getWidth() /
2
;
//
减去游标
1/2 的长度...
75
}
else
if
(NowX <
0
) {
76
x =
0
;
77
}
else
{
78
x = NowX - slip_btn.getWidth() /
2
;