reflashInfoRL.setOnTouchListener(new View.OnTouchListener(){ @Override public boolean onTouch(View v, MotionEvent event){ // TODO Auto-generated method stub x = event.getRawX(); y = event.getRawY()-25; //25是系统状态栏的高度 switch (event.getAction()) { case MotionEvent.ACTION_DOWN: //按下 reflashInfoRL.setBackgroundColor(getResources().getColor(R.color.gray)); //获取相对View的坐标,即以此View左上角为原点 mTouchStartX = event.getX(); mTouchStartY = event.getY(); break; case MotionEvent.ACTION_MOVE: //移动 break; case MotionEvent.ACTION_UP: //抬起 reflashInfoRL.setBackgroundColor(getResources().getColor(R.color.white)); if(Math.abs(event.getY()-mTouchStartY)<5) { mTouchStartX=mTouchStartY=0; new AlertDialog.Builder(getApplicationContext()) .setTitle("提醒").setMessage("确定要从服务器下载更新通讯录?") .setNegativeButton("取消", null) .setPositiveButton("确定", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub getAddressInfo(); } }).show(); } break; } return true; } });