想在Gallery 开始滑动时和滑动结束时做一些处理,就需要知道滑动开始和停止的时机
1.开始的时机
Gallery mCoverFlowView = new Gallery(context);
final GestureDetectorCompat mGestureDetectorCompat = new GestureDetectorCompat(this, this);
mCoverFlowView.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return mGestureDetectorCompat.onTouchEvent(event);
}
});
});
然后可以在OnGestureListener中的
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
float distanceY) {
//添加滑动开始时 处理逻辑
return false;
}
2.判断gallery 何时停止
mCoverFlowView.setCallbackDuringFling(false);
mCoverFlowView.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view,
int position, long id) {
//添加滑动结束 处理逻辑
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});