sinat_34245223
blast_z
采纳率42.9%
2016-09-07 13:12 阅读 2.7k
已采纳

GestureDetector没用 滑动屏幕没反应

1

public class AttributeActivity extends Activity implements GestureDetector.OnGestureListener{
private ListView listView;
private static final int FLIP_DISTANCE=80;
private GestureDetector detector;
List persons;
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.attribute_main);
detector=new GestureDetector(AttributeActivity.this,AttributeActivity.this);
Intent intent=getIntent();
Bundle data=intent.getExtras();
persons=(List)data.getSerializable("MainActivity_persons");
listView=(ListView)findViewById(R.id.listView_attribute_main);
PersonAdapter personAdapter=new PersonAdapter(AttributeActivity.this,R.layout.list_item,persons);
listView.setAdapter(personAdapter);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
return detector.onTouchEvent(event);
}

@Override
public void onShowPress(MotionEvent e) {

}

@Override
public void onLongPress(MotionEvent e) {

}

@Override
public boolean onSingleTapUp(MotionEvent e) {
    return false;
}

@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
    return false;
}

@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
    Toast.makeText(AttributeActivity.this, "onFling()", Toast.LENGTH_SHORT).show();
    if(e2.getX()-e1.getX()>=FLIP_DISTANCE){
        Intent intent=new Intent(AttributeActivity.this,MainActivity.class);
        startActivity(intent);
        return true;
    }
    return false;
}

@Override
public boolean onDown(MotionEvent e) {
    return false;
}

}

滑了滑屏幕没反应 哪里有问题

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

2条回答 默认 最新

  • 已采纳
    jjxojm DreamerJ 2016-09-07 13:50
    @Override
        public boolean dispatchTouchEvent(MotionEvent ev) {
            detector.onTouchEvent(event);
            super.dispatchTouchEvent(ev);
            return false;
        } 
    
    点赞 1 评论 复制链接分享
  • jjxojm DreamerJ 2016-09-07 13:29

    看你的布局文件中有ListView,应该是ListView已经处理了你的触摸事件,所以Activity中的onTouchEvent方法并没有执行。
    你可以试试在ListView以外的屏幕上进行触摸操作,看看是否有反应。

    点赞 评论 复制链接分享

相关推荐