开发者

How do I set an OnTouchListener for a relativeLayout?

开发者 https://www.devze.com 2023-03-17 02:44 出处:网络
I want to capture two events from a relativeLayout. When the user clicks it and when the user releases his click (like mousedown/mouseup)

I want to capture two events from a relativeLayout. When the user clicks it and when the user releases his click (like mousedown/mouseup)

    rl.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            //
        }
    });
开发者_如何学C

I tried setting up something like:

            if(event == MotionEvent.ACTION_DOWN) {

            }

But eclipse just throws an error about an incompatible operand type. Anyone who knows how to do this?


Try...

if (event.getAction() == MotionEvent.ACTION_DOWN) {
    ...
}
0

精彩评论

暂无评论...
验证码 换一张
取 消