I am attempting to move and grow, a RecyclerView so that the contents take up the full screen base on touch input. I want the RecyclerView to maintain the ability to scroll left and right.
I was unable to get a GestureDetector to work properly with the RecyclerView. Catching the onScrollChange doesn't work as it may not have the ability to scroll. I attempting onTouchEvent but the results were rather buggy. Does anyone have any advice?
Repo: https://github.com/CubanAzcuy/Animation-Test
mListView.setOnTouchListener(new View.OnTouchListener() {
Float mHistoricX = null;
Float mHistoricY = null;
Float mHistoricX2 = null;
Float mHistoricY2 = null;
int mScrollDirection = 0;
//1 = Left Right
//2 = Up Down
@Override
public boolean onTouch(View v, MotionEvent e) {
Log.d("TAG", "eX: " + e.getX() + " eY: " + e.getY());
switch (e.getAction()) {
case MotionEvent.ACTION_UP:
Log.d("TAG", "ACTION_UP");
mHistoricX = null;
mHistoricY = null;
mScrollDirection = 0;
break;
case MotionEvent.ACTION_MOVE:
Log.d("TAG", "ACTION_MOVE");
if(mHistoricX == null || mHistoricY == null) {
mHistoricX = e.getX();
mHistoricY = e.getY();
} else {
if(mScrollDirection == 0) {
float tempX = Math.abs(mHistoricX - e.getX());
float tempy = Math.abs(mHistoricY - e.getY());
if(tempX >= tempy) {
mScrollDirection = 1;
} else {
mScrollDirection = 2;
}
mHistoricX2 = mHistoricX - e.getX();
mHistoricY2 = mHistoricY - e.getY();
} else {
mHistoricX2 = mHistoricX - e.getX();
mHistoricY2 = mHistoricY - e.getY();
Log.d("TAG", "X: " + mHistoricX2 + " Y: " + mHistoricY2);
mHistoricX = e.getX();
mHistoricY = e.getY();
}
}
break;
default:
break;
}
if(mScrollDirection == 2){
mListView.animate().setDuration(0).xBy(-mHistoricX2).yBy(-mHistoricY2);
return true;
}
return false;
}
});