Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我们的 relativeLayout 上有一个 onClick 函数,但是当我们将手指从屏幕上松开时(onTouchEnd)会触发该方法。我们希望我们的函数在我的手指触摸屏幕的那一刻触发。
android:clickable="true" android:onClick="click" public void click(View v){ releaseItem(); }
利用View.setOnToucListener(listener)
View.setOnToucListener(listener)
yourRelativeLayout.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if(event.getAction() == MotionEvent.ACTION_DOWN){ //Your stuff here return true; } return false; } });