I'm looking for a solution to detect the endposition from an onScroll gesture. I found just this but I don't want it on a specific view, than more on an activity that implements an OnGestureListener overall. What is the best way to solve this Problem?
My code so fare:
public class MyActivity extends Activity implements OnGestureListener {
private GestureDetector myGesture;
private RelativeLayout rl;
private LinearLayout ll;
private LinearLayout lltest;
private HorizontalScrollView hsv;
private CardView cv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my);
rl = (RelativeLayout) findViewById(R.id.rl);
ll = (LinearLayout) findViewById(R.id.ll);
lltest = (LinearLayout) findViewById(R.id.lltest);
cv = (CardView) findViewById(R.id.card1);
hsv = (HorizontalScrollView) findViewById(R.id.hsv);
myGesture =new GestureDetector(this);
LayoutTransition transition = lltest.getLayoutTransition();
transition.setDuration(500);
transition.enableTransitionType(LayoutTransition.CHANGING);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
return myGesture.onTouchEvent(event);
}
@Override
public boolean onDown(MotionEvent e) {
return false;
}
@Override
public void onShowPress(MotionEvent e) {
}
@Override
public boolean onSingleTapUp(MotionEvent e) {
return false;
}
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
Log.d("!!!!!", e1.toString());
//Log.d("?????", e2.toString());
if (e1.getX() > 1030) {
Log.d("!!!!!", "Edge fling!");
TextView text = (TextView) findViewById(R.id.text);
text.setText("swiped!!!!!");
HorizontalScrollView hsv = (HorizontalScrollView) findViewById(R.id.hsv);
hsv.setVisibility(View.VISIBLE);
}
return true;
}
@Override
public void onLongPress(MotionEvent e) {
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
return false;
}
public void klick(View view) {
LinearLayout.LayoutParams params = (LinearLayout.LayoutParams)
cv.getLayoutParams();
params.height = 200;
cv.setLayoutParams(params);
}
}