background image

 

 9

 import android.util.AttributeSet;

 

10

 import android.util.Log;

 

11

 import android.view.MotionEvent;

12

 import android.view.View;

13

 import android.view.View.OnTouchListener;

 

14

 

 

15

 import com.view.SlipButton.R;

 

16

 

 

17

 

public

 

class

SlipButton extends View implements OnTouchListener {

18

 

 

19

     

private

 

float

 DownX, NowX;

//

 

按下时的

x,当前的 x

 

20

     

private

 

float

 btn_on_left = 

0

;

21

     

private

 

float

 btn_off_left = 

0

;

22

 

 

23

     

private

 boolean NowChoose = 

false

;

//记录当前按钮是否打开,true 为打开,flase 为关闭

 

24

     

private

boolean isChecked;

25

     

private

 boolean OnSlip = 

false

;

//

 

记录用户是否在滑动的变量

 

26

     

private

 boolean isChgLsnOn = 

false

;

27

 

 

28

     

private

 OnChangedListener ChgLsn;

29

     

private

 Bitmap bg_on;

30

     

private

Bitmap bg_off;

31

     

private

 Bitmap slip_btn;

32

 

 

33

     

public

 SlipButton(Context context) {

 

34

        super(context);

35

        init();

36

    }

37

 

 

38

     

public

 SlipButton(Context context, AttributeSet attrs) {

 

39

        super(context, attrs);

40

        init();

 

41

    }

42

 

 

43

     

private

 

void

 init() { 

//

 

初始化

 

44

         bg_on = BitmapFactory.decodeResource(getResources(),