想做一个android的launcher,实现左右滑动屏幕,发现在虚拟机上面只能实现鼠标滑动,方向键不可以切换页面
希望大家踊跃发言,要求实现方向键或者说D-pad实现左右页面的切换,手势可以不用实现。privatevoidbindDetector(){detector=newGest...
希望大家踊跃发言,要求实现方向键或者说D-pad实现左右页面的切换,手势可以不用实现。
private void bindDetector(){
detector = new GestureDetector(new OnGestureListener() {
@Override
public boolean onSingleTapUp(MotionEvent e) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "!!左右滑动,发现不同!!", Toast.LENGTH_SHORT).show();
return false;
}
@Override
public void onShowPress(MotionEvent e) {
// TODO Auto-generated method stub
}
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
float distanceY) {
// TODO Auto-generated method stub
return false;
}
@Override
public void onLongPress(MotionEvent e) {
// TODO Auto-generated method stub
//Toast.makeText(getApplicationContext(), "LongPressd", Toast.LENGTH_SHORT).show();
}
@Override
public boolean onDown(MotionEvent e) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
Log.v("tag", ">>>>>>>>>>>>>>>>>velocityX>>>"+velocityX);
if(e1.getX() - e2.getX() > 120){
myFlipper.setInAnimation(getApplicationContext(), R.anim.push_left_in);
myFlipper.setOutAnimation(getApplicationContext(), R.anim.push_left_out);
myFlipper.showPrevious();
}else if(e1.getX() - e2.getX() < -120) {
myFlipper.setInAnimation(getApplicationContext(), R.anim.push_right_in);
myFlipper.setOutAnimation(getApplicationContext(), R.anim.push_right_out);
myFlipper.showNext();
}
return false;
}
});
}
@Override
public boolean onTouchEvent(MotionEvent event) {
return this.detector.onTouchEvent(event);
}
这段是gueturDetector的代码。
如何用d-pad实现。
谢谢。 展开
private void bindDetector(){
detector = new GestureDetector(new OnGestureListener() {
@Override
public boolean onSingleTapUp(MotionEvent e) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "!!左右滑动,发现不同!!", Toast.LENGTH_SHORT).show();
return false;
}
@Override
public void onShowPress(MotionEvent e) {
// TODO Auto-generated method stub
}
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
float distanceY) {
// TODO Auto-generated method stub
return false;
}
@Override
public void onLongPress(MotionEvent e) {
// TODO Auto-generated method stub
//Toast.makeText(getApplicationContext(), "LongPressd", Toast.LENGTH_SHORT).show();
}
@Override
public boolean onDown(MotionEvent e) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
Log.v("tag", ">>>>>>>>>>>>>>>>>velocityX>>>"+velocityX);
if(e1.getX() - e2.getX() > 120){
myFlipper.setInAnimation(getApplicationContext(), R.anim.push_left_in);
myFlipper.setOutAnimation(getApplicationContext(), R.anim.push_left_out);
myFlipper.showPrevious();
}else if(e1.getX() - e2.getX() < -120) {
myFlipper.setInAnimation(getApplicationContext(), R.anim.push_right_in);
myFlipper.setOutAnimation(getApplicationContext(), R.anim.push_right_out);
myFlipper.showNext();
}
return false;
}
});
}
@Override
public boolean onTouchEvent(MotionEvent event) {
return this.detector.onTouchEvent(event);
}
这段是gueturDetector的代码。
如何用d-pad实现。
谢谢。 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询