A button to capture and ACTION_UP ACTION_DOWN touch screen operation, down to the button when setting a bright background in the up position when setting a gray background, and why, when clicking quickly (like double) is not normal? The results highlight the background image is always displayed, why ah? ? ?
case R.id.ptz_down_btn:
switch (event.getAction ()) {
case MotionEvent.ACTION_DOWN :/ / Screen Press
Log.e ("11111111111", "11111111111");
down_btn.setBackgroundDrawable (this.getResources (). getDrawable (
R.drawable.ptz_down_focus)) ;/ / button pressed highlight background image, click on and then set when lifting gray;
break;
case MotionEvent.ACTION_UP :/ / Press lifted
Log.e ("22222", "2222222222222");
down_btn.setBackgroundDrawable (this.getResources ()
. getDrawable (R.drawable.ptz_down_blur)) ;/ / button pressed highlight background image, click on and then set when lifting gray;
break;
}
break;
----------------------------------------
R.id.ptz_down_btn is a button? Why do you use event.getAction () do touch judge?
Why not
Java code
button.setOnClickListener (new OnClickListener () {
@ Override
public void onClick (View v) {
/ / Here to see to sense the time the button is pressed
}
});
If you really want to use event.getAction ()
Should override the parent class method onTouchEvent
Java code
/ / Here the judge is pressed! ! !
@ Override
public boolean onTouchEvent (MotionEvent event) {
/ / Get the coordinates of the touch
int x = (int) event.getX ();
int y = (int) event.getY ();
switch (event.getAction ()) {
/ / Touch screen moments
case MotionEvent.ACTION_DOWN:
UpdateTouchEvent (x, y);
break;
/ / Touch and move the moment
case MotionEvent.ACTION_MOVE:
break;
/ / End touch moments
case MotionEvent.ACTION_UP:
break;
}
return super.onTouchEvent (event);
}
The desire to help the landlord! !
------------------------------------------------
Double-click the listener achieve
没有评论:
发表评论