我正在开发一个Android应用程序,希望在其中滑动手指即可滑动图像。我已经实现了onClickListener可以滑动图像的,但是我不知道如何实现手指触摸功能。
onClickListener
请给我建议任何方法,如何用手指滑动图像。任何建议或任何教程或方法都将有所帮助。
您可以使用onTouchListner方法代替onClickListner。下面给出了onTouchListners示例。
public class abc extends Activity implements OnTouchListener { ImageView img; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.one); img = (ImageView) findViewById(R.id.imageView1); img.setOnTouchListener(this); } public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: { // Here u can write code which is executed after the user touch on the screen break; } case MotionEvent.ACTION_UP: { // Here u can write code which is executed after the user release the touch on the screen break; } case MotionEvent.ACTION_MOVE: { // Here u can write code which is executed when user move the finger on the screen break; } } return true; }