java onScroll方法不起作用
public class showManga extends Activity implements GestureDetector.OnGestureListener{
GestureDetectorCompat detector;
TextView text;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
text=(TextView)findViewById(R.id.text);
setContentView(R.layout.image);
this.detector=new GestureDetectorCompat(this,this);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
this.detector.onTouchEvent(event);
return super.onTouchEvent(event);
}
@Override
public boolean onDown(MotionEvent arg0) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean onFling(MotionEvent start, MotionEvent finish, float velocityX,
float velocityY) {
// TODO Auto-generated method stub
return false;
}
@Override
public void onLongPress(MotionEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public boolean onScroll(MotionEvent arg0, MotionEvent arg1, float arg2,
float arg3) {
// TODO Auto-generated method stub
text.setText("scroll");
return true;
}
@Override
public void onShowPress(MotionEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public boolean onSingleTapUp(MotionEvent arg0) {
// TODO Auto-generated method stub
return false;
}
}
我不明白为什么这个代码不起作用。我检查了一切。对我来说似乎是对的。请帮帮我。onScroll
方法不起作用
# 1 楼答案
将此行放在setcontent视图之后
比如: