此代码适用于 2.3.5 的手机,但不适用于 4.0.3 的平板电脑:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
this.setContentView(R.layout.rotate_image);
mRotator = (ImageView) findViewById(R.id.rotateImage_image_rotator);
mGDetector = new GestureDetector(getApplicationContext(), this);
findViewById(R.id.rotateImage_background).setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return mGDetector.onTouchEvent(event);
}
});
}
@Override
public boolean onDown(MotionEvent e) {
// TODO Auto-generated method stub
return true;
}
@Override
public boolean onFling(MotionEvent start, MotionEvent finish, float velocityX, float velocityY) {
return false;
}
@Override
public void onLongPress(MotionEvent e) {
// TODO Auto-generated method stub
}
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
float distanceY) {
if(e2.getHistorySize() == 0){
}
else{
if(e2.getX() > e2.getHistoricalX(e2.getHistorySize() -1)){
updateRotation(true);
}
else{
updateRotation(false);
}
}
return true;
}
@Override
public void onShowPress(MotionEvent e) {
// TODO Auto-generated method stub
}
@Override
public boolean onSingleTapUp(MotionEvent e) {
// TODO Auto-generated method stub
return false;
}
平板电脑有什么错误吗?我的意思是,它的代码相同,它可以在手机上完美运行,但它不会在平板电脑上注册。是因为安卓版,还是因为是平板?
编辑:更具体地说,由于某种原因,onScroll 函数不会在平板电脑上被调用或只被调用一次,但在手机上就像一个魅力