Struggling with onTouchListenerAndroid: How to handle right to left swipe gesturesError with OnTouchListeneronTouchListener not workingImplementing my own OnTouchListenerCannot set OnTouchListenerAndroid onTouchListenerOnTouchListener not calledonTouchListener warning: onTouch should call View#performClick when a click is detectedIs OnTouchListener faster than OnClickListener?onTouchListener is not workingOnTouchListener will not be triggered

Why "be dealt cards" rather than "be dealing cards"?

Is it correct to write "is not focus on"?

Is this Spell Mimic feat balanced?

What't the meaning of this extra silence?

What is the opposite of 'gravitas'?

voltage of sounds of mp3files

How can I use the arrow sign in my bash prompt?

Is the destination of a commercial flight important for the pilot?

Can somebody explain Brexit in a few child-proof sentences?

Efficiently merge handle parallel feature branches in SFDX

Is there a good way to store credentials outside of a password manager?

Bash method for viewing beginning and end of file

Trouble understanding overseas colleagues

Lay out the Carpet

Is HostGator storing my password in plaintext?

The plural of 'stomach"

Modify casing of marked letters

What is the oldest known work of fiction?

What defines a dissertation?

Hostile work environment after whistle-blowing on coworker and our boss. What do I do?

Why are on-board computers allowed to change controls without notifying the pilots?

Applicability of Single Responsibility Principle

Do there exist finite commutative rings with identity that are not Bézout rings?

Greatest common substring



Struggling with onTouchListener


Android: How to handle right to left swipe gesturesError with OnTouchListeneronTouchListener not workingImplementing my own OnTouchListenerCannot set OnTouchListenerAndroid onTouchListenerOnTouchListener not calledonTouchListener warning: onTouch should call View#performClick when a click is detectedIs OnTouchListener faster than OnClickListener?onTouchListener is not workingOnTouchListener will not be triggered













1















I have a ViewFlipper, on wich I want to set a touchListener. It is inside a ScrollView, (below the ViewFlipper there are more UI elements) and I want that if the user makes a vertical movement, the scrollview acts, and when the user makes a horizontal movement, the ViewFlipper acts. (The components are added dynamically in the ViewFlipper).



For clarification, this is the layout:



<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/parentrl">



<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">

<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">

<ViewFlipper
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/vflipper"
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
android:layout_marginTop="20dp"
android:background="@drawable/flightcomponentborder">


</ViewFlipper>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/inforecogida"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:text="@string/inforecogida"
android:textColor="@color/actionbardefaultcolor"
android:layout_below="@+id/vflipper"/>

<ImageView
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_below="@+id/inforecogida"
android:id="@+id/separador"
android:background="@color/gris"
android:layout_marginTop="10dp"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/personaheader"
android:layout_below="@+id/separador"
android:layout_marginTop="10dp"
android:layout_alignStart="@+id/inforecogida"
android:text="@string/persona"
android:textColor="@color/actionbardefaultcolor"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/persona"
android:layout_below="@+id/personaheader"
android:layout_alignStart="@+id/inforecogida"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/infotext"
android:layout_alignStart="@+id/inforecogida"
android:layout_below="@+id/persona"
android:text="@string/infotext"
android:textStyle="italic"/>

</RelativeLayout>

</ScrollView>



</RelativeLayout>


This is the TouchListener I am adding to the ViewFlipper:



parentListener = new View.OnTouchListener()
@Override
public boolean onTouch(View v, MotionEvent event)
int action = event.getActionMasked();
switch (action)
case MotionEvent.ACTION_DOWN:
startX = event.getX();
startY = event.getRawY();

break;


case MotionEvent.ACTION_UP:

endX = event.getX();
endY = event.getRawY();
int movX;//0=swipe izq 1=swipe right
int movY;
if(startX-endX < 0)
movX=0;
Log.i("David", "Swipe left action up");
float totalPixelsX=Math.abs(startX-endX);
float totalPixelsY=event.getRawY() - startY;
Log.i("David", "totalPixelsx: "+totalPixelsX);
Log.i("David", "totalPixelsY: "+totalPixelsY);
if(totalPixelsY<0)
Log.i("David", "scroll down");
totalPixelsY=event.getRawY() - startY;
Log.i("David", "We moved "+totalPixelsY+" pixels");
else
Log.i("David", "scroll up");
Log.i("David", "We moved "+totalPixelsY+" pixels");

else
movX=1;
Log.i("David", "Swipe right action up");
float totalPixelsX=Math.abs(startX-endX);
float totalPixelsY=event.getRawY() - startY;
Log.i("David", "totalPixelsx: "+totalPixelsX);
Log.i("David", "totalPixelsY: "+totalPixelsY);
if(totalPixelsY<0)
Log.i("David", "scroll down");
totalPixelsY=event.getRawY() - startY;
Log.i("David", "We moved "+totalPixelsY+" pixels");
else
Log.i("David", "scroll up");
Log.i("David", "We moved "+totalPixelsY+" pixels");


Log.i("David", "haveFlipped false");
haveFlipped=false;
break;

case MotionEvent.ACTION_CANCEL:
endX = event.getX();
endY = event.getRawY();
if(startX-endX < 0)
movX=0;
Log.i("David", "Swipe left action cancel");
float totalPixelsX=Math.abs(startX-endX);
float totalPixelsY=event.getRawY() - startY;
Log.i("David", "totalPixelsx: "+totalPixelsX);
Log.i("David", "totalPixelsY: "+totalPixelsY);
if(totalPixelsY<0)
Log.i("David", "scroll down");
totalPixelsY=event.getRawY() - startY;
Log.i("David", "We moved "+totalPixelsY+" pixels");
else
Log.i("David", "scroll up");
Log.i("David", "We moved "+totalPixelsY+" pixels");

else
movX=1;
Log.i("David", "Swipe right action cancel");
float totalPixelsX=Math.abs(startX-endX);
float totalPixelsY=event.getRawY() - startY;
Log.i("David", "totalPixelsx: "+totalPixelsX);
Log.i("David", "totalPixelsY: "+totalPixelsY);
if(totalPixelsY<0)
Log.i("David", "scroll down");
totalPixelsY=event.getRawY() - startY;
Log.i("David", "We moved "+totalPixelsY+" pixels");
else
Log.i("David", "scroll up");


Log.i("David", "haveFlipped false");
haveFlipped=false;
break;


return true;

;


My problem is, the action_cancel or action_up are called BEFORE my finger lifts from the phone screen, so the amount of movement in Y axis is always smaller than the actual movement of my finger.



What I plan to achieve is that, when the amount of X > amount of y, use the ViewFlipper, and when the amount of X < amount of y, leave the ScrollView do his job.



I don't know if my approach is correct. Could anyone tell my why action_up and action_cancel are called before I lift my finger? And how to achieve my goal?



Thank you.










share|improve this question
























  • Try this this it has issues as you seem to have

    – raj kavadia
    Mar 7 at 12:27











  • You should try to inverse the scrollView and the ViewFlipper. A ViewFlipper probably was designed to contain scrollable Views while the ScrollView shouldn't have any scrollable content inside.

    – Maxouille
    Mar 7 at 12:29















1















I have a ViewFlipper, on wich I want to set a touchListener. It is inside a ScrollView, (below the ViewFlipper there are more UI elements) and I want that if the user makes a vertical movement, the scrollview acts, and when the user makes a horizontal movement, the ViewFlipper acts. (The components are added dynamically in the ViewFlipper).



For clarification, this is the layout:



<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/parentrl">



<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">

<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">

<ViewFlipper
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/vflipper"
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
android:layout_marginTop="20dp"
android:background="@drawable/flightcomponentborder">


</ViewFlipper>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/inforecogida"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:text="@string/inforecogida"
android:textColor="@color/actionbardefaultcolor"
android:layout_below="@+id/vflipper"/>

<ImageView
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_below="@+id/inforecogida"
android:id="@+id/separador"
android:background="@color/gris"
android:layout_marginTop="10dp"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/personaheader"
android:layout_below="@+id/separador"
android:layout_marginTop="10dp"
android:layout_alignStart="@+id/inforecogida"
android:text="@string/persona"
android:textColor="@color/actionbardefaultcolor"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/persona"
android:layout_below="@+id/personaheader"
android:layout_alignStart="@+id/inforecogida"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/infotext"
android:layout_alignStart="@+id/inforecogida"
android:layout_below="@+id/persona"
android:text="@string/infotext"
android:textStyle="italic"/>

</RelativeLayout>

</ScrollView>



</RelativeLayout>


This is the TouchListener I am adding to the ViewFlipper:



parentListener = new View.OnTouchListener()
@Override
public boolean onTouch(View v, MotionEvent event)
int action = event.getActionMasked();
switch (action)
case MotionEvent.ACTION_DOWN:
startX = event.getX();
startY = event.getRawY();

break;


case MotionEvent.ACTION_UP:

endX = event.getX();
endY = event.getRawY();
int movX;//0=swipe izq 1=swipe right
int movY;
if(startX-endX < 0)
movX=0;
Log.i("David", "Swipe left action up");
float totalPixelsX=Math.abs(startX-endX);
float totalPixelsY=event.getRawY() - startY;
Log.i("David", "totalPixelsx: "+totalPixelsX);
Log.i("David", "totalPixelsY: "+totalPixelsY);
if(totalPixelsY<0)
Log.i("David", "scroll down");
totalPixelsY=event.getRawY() - startY;
Log.i("David", "We moved "+totalPixelsY+" pixels");
else
Log.i("David", "scroll up");
Log.i("David", "We moved "+totalPixelsY+" pixels");

else
movX=1;
Log.i("David", "Swipe right action up");
float totalPixelsX=Math.abs(startX-endX);
float totalPixelsY=event.getRawY() - startY;
Log.i("David", "totalPixelsx: "+totalPixelsX);
Log.i("David", "totalPixelsY: "+totalPixelsY);
if(totalPixelsY<0)
Log.i("David", "scroll down");
totalPixelsY=event.getRawY() - startY;
Log.i("David", "We moved "+totalPixelsY+" pixels");
else
Log.i("David", "scroll up");
Log.i("David", "We moved "+totalPixelsY+" pixels");


Log.i("David", "haveFlipped false");
haveFlipped=false;
break;

case MotionEvent.ACTION_CANCEL:
endX = event.getX();
endY = event.getRawY();
if(startX-endX < 0)
movX=0;
Log.i("David", "Swipe left action cancel");
float totalPixelsX=Math.abs(startX-endX);
float totalPixelsY=event.getRawY() - startY;
Log.i("David", "totalPixelsx: "+totalPixelsX);
Log.i("David", "totalPixelsY: "+totalPixelsY);
if(totalPixelsY<0)
Log.i("David", "scroll down");
totalPixelsY=event.getRawY() - startY;
Log.i("David", "We moved "+totalPixelsY+" pixels");
else
Log.i("David", "scroll up");
Log.i("David", "We moved "+totalPixelsY+" pixels");

else
movX=1;
Log.i("David", "Swipe right action cancel");
float totalPixelsX=Math.abs(startX-endX);
float totalPixelsY=event.getRawY() - startY;
Log.i("David", "totalPixelsx: "+totalPixelsX);
Log.i("David", "totalPixelsY: "+totalPixelsY);
if(totalPixelsY<0)
Log.i("David", "scroll down");
totalPixelsY=event.getRawY() - startY;
Log.i("David", "We moved "+totalPixelsY+" pixels");
else
Log.i("David", "scroll up");


Log.i("David", "haveFlipped false");
haveFlipped=false;
break;


return true;

;


My problem is, the action_cancel or action_up are called BEFORE my finger lifts from the phone screen, so the amount of movement in Y axis is always smaller than the actual movement of my finger.



What I plan to achieve is that, when the amount of X > amount of y, use the ViewFlipper, and when the amount of X < amount of y, leave the ScrollView do his job.



I don't know if my approach is correct. Could anyone tell my why action_up and action_cancel are called before I lift my finger? And how to achieve my goal?



Thank you.










share|improve this question
























  • Try this this it has issues as you seem to have

    – raj kavadia
    Mar 7 at 12:27











  • You should try to inverse the scrollView and the ViewFlipper. A ViewFlipper probably was designed to contain scrollable Views while the ScrollView shouldn't have any scrollable content inside.

    – Maxouille
    Mar 7 at 12:29













1












1








1








I have a ViewFlipper, on wich I want to set a touchListener. It is inside a ScrollView, (below the ViewFlipper there are more UI elements) and I want that if the user makes a vertical movement, the scrollview acts, and when the user makes a horizontal movement, the ViewFlipper acts. (The components are added dynamically in the ViewFlipper).



For clarification, this is the layout:



<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/parentrl">



<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">

<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">

<ViewFlipper
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/vflipper"
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
android:layout_marginTop="20dp"
android:background="@drawable/flightcomponentborder">


</ViewFlipper>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/inforecogida"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:text="@string/inforecogida"
android:textColor="@color/actionbardefaultcolor"
android:layout_below="@+id/vflipper"/>

<ImageView
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_below="@+id/inforecogida"
android:id="@+id/separador"
android:background="@color/gris"
android:layout_marginTop="10dp"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/personaheader"
android:layout_below="@+id/separador"
android:layout_marginTop="10dp"
android:layout_alignStart="@+id/inforecogida"
android:text="@string/persona"
android:textColor="@color/actionbardefaultcolor"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/persona"
android:layout_below="@+id/personaheader"
android:layout_alignStart="@+id/inforecogida"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/infotext"
android:layout_alignStart="@+id/inforecogida"
android:layout_below="@+id/persona"
android:text="@string/infotext"
android:textStyle="italic"/>

</RelativeLayout>

</ScrollView>



</RelativeLayout>


This is the TouchListener I am adding to the ViewFlipper:



parentListener = new View.OnTouchListener()
@Override
public boolean onTouch(View v, MotionEvent event)
int action = event.getActionMasked();
switch (action)
case MotionEvent.ACTION_DOWN:
startX = event.getX();
startY = event.getRawY();

break;


case MotionEvent.ACTION_UP:

endX = event.getX();
endY = event.getRawY();
int movX;//0=swipe izq 1=swipe right
int movY;
if(startX-endX < 0)
movX=0;
Log.i("David", "Swipe left action up");
float totalPixelsX=Math.abs(startX-endX);
float totalPixelsY=event.getRawY() - startY;
Log.i("David", "totalPixelsx: "+totalPixelsX);
Log.i("David", "totalPixelsY: "+totalPixelsY);
if(totalPixelsY<0)
Log.i("David", "scroll down");
totalPixelsY=event.getRawY() - startY;
Log.i("David", "We moved "+totalPixelsY+" pixels");
else
Log.i("David", "scroll up");
Log.i("David", "We moved "+totalPixelsY+" pixels");

else
movX=1;
Log.i("David", "Swipe right action up");
float totalPixelsX=Math.abs(startX-endX);
float totalPixelsY=event.getRawY() - startY;
Log.i("David", "totalPixelsx: "+totalPixelsX);
Log.i("David", "totalPixelsY: "+totalPixelsY);
if(totalPixelsY<0)
Log.i("David", "scroll down");
totalPixelsY=event.getRawY() - startY;
Log.i("David", "We moved "+totalPixelsY+" pixels");
else
Log.i("David", "scroll up");
Log.i("David", "We moved "+totalPixelsY+" pixels");


Log.i("David", "haveFlipped false");
haveFlipped=false;
break;

case MotionEvent.ACTION_CANCEL:
endX = event.getX();
endY = event.getRawY();
if(startX-endX < 0)
movX=0;
Log.i("David", "Swipe left action cancel");
float totalPixelsX=Math.abs(startX-endX);
float totalPixelsY=event.getRawY() - startY;
Log.i("David", "totalPixelsx: "+totalPixelsX);
Log.i("David", "totalPixelsY: "+totalPixelsY);
if(totalPixelsY<0)
Log.i("David", "scroll down");
totalPixelsY=event.getRawY() - startY;
Log.i("David", "We moved "+totalPixelsY+" pixels");
else
Log.i("David", "scroll up");
Log.i("David", "We moved "+totalPixelsY+" pixels");

else
movX=1;
Log.i("David", "Swipe right action cancel");
float totalPixelsX=Math.abs(startX-endX);
float totalPixelsY=event.getRawY() - startY;
Log.i("David", "totalPixelsx: "+totalPixelsX);
Log.i("David", "totalPixelsY: "+totalPixelsY);
if(totalPixelsY<0)
Log.i("David", "scroll down");
totalPixelsY=event.getRawY() - startY;
Log.i("David", "We moved "+totalPixelsY+" pixels");
else
Log.i("David", "scroll up");


Log.i("David", "haveFlipped false");
haveFlipped=false;
break;


return true;

;


My problem is, the action_cancel or action_up are called BEFORE my finger lifts from the phone screen, so the amount of movement in Y axis is always smaller than the actual movement of my finger.



What I plan to achieve is that, when the amount of X > amount of y, use the ViewFlipper, and when the amount of X < amount of y, leave the ScrollView do his job.



I don't know if my approach is correct. Could anyone tell my why action_up and action_cancel are called before I lift my finger? And how to achieve my goal?



Thank you.










share|improve this question
















I have a ViewFlipper, on wich I want to set a touchListener. It is inside a ScrollView, (below the ViewFlipper there are more UI elements) and I want that if the user makes a vertical movement, the scrollview acts, and when the user makes a horizontal movement, the ViewFlipper acts. (The components are added dynamically in the ViewFlipper).



For clarification, this is the layout:



<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/parentrl">



<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">

<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">

<ViewFlipper
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/vflipper"
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
android:layout_marginTop="20dp"
android:background="@drawable/flightcomponentborder">


</ViewFlipper>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/inforecogida"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:text="@string/inforecogida"
android:textColor="@color/actionbardefaultcolor"
android:layout_below="@+id/vflipper"/>

<ImageView
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_below="@+id/inforecogida"
android:id="@+id/separador"
android:background="@color/gris"
android:layout_marginTop="10dp"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/personaheader"
android:layout_below="@+id/separador"
android:layout_marginTop="10dp"
android:layout_alignStart="@+id/inforecogida"
android:text="@string/persona"
android:textColor="@color/actionbardefaultcolor"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/persona"
android:layout_below="@+id/personaheader"
android:layout_alignStart="@+id/inforecogida"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/infotext"
android:layout_alignStart="@+id/inforecogida"
android:layout_below="@+id/persona"
android:text="@string/infotext"
android:textStyle="italic"/>

</RelativeLayout>

</ScrollView>



</RelativeLayout>


This is the TouchListener I am adding to the ViewFlipper:



parentListener = new View.OnTouchListener()
@Override
public boolean onTouch(View v, MotionEvent event)
int action = event.getActionMasked();
switch (action)
case MotionEvent.ACTION_DOWN:
startX = event.getX();
startY = event.getRawY();

break;


case MotionEvent.ACTION_UP:

endX = event.getX();
endY = event.getRawY();
int movX;//0=swipe izq 1=swipe right
int movY;
if(startX-endX < 0)
movX=0;
Log.i("David", "Swipe left action up");
float totalPixelsX=Math.abs(startX-endX);
float totalPixelsY=event.getRawY() - startY;
Log.i("David", "totalPixelsx: "+totalPixelsX);
Log.i("David", "totalPixelsY: "+totalPixelsY);
if(totalPixelsY<0)
Log.i("David", "scroll down");
totalPixelsY=event.getRawY() - startY;
Log.i("David", "We moved "+totalPixelsY+" pixels");
else
Log.i("David", "scroll up");
Log.i("David", "We moved "+totalPixelsY+" pixels");

else
movX=1;
Log.i("David", "Swipe right action up");
float totalPixelsX=Math.abs(startX-endX);
float totalPixelsY=event.getRawY() - startY;
Log.i("David", "totalPixelsx: "+totalPixelsX);
Log.i("David", "totalPixelsY: "+totalPixelsY);
if(totalPixelsY<0)
Log.i("David", "scroll down");
totalPixelsY=event.getRawY() - startY;
Log.i("David", "We moved "+totalPixelsY+" pixels");
else
Log.i("David", "scroll up");
Log.i("David", "We moved "+totalPixelsY+" pixels");


Log.i("David", "haveFlipped false");
haveFlipped=false;
break;

case MotionEvent.ACTION_CANCEL:
endX = event.getX();
endY = event.getRawY();
if(startX-endX < 0)
movX=0;
Log.i("David", "Swipe left action cancel");
float totalPixelsX=Math.abs(startX-endX);
float totalPixelsY=event.getRawY() - startY;
Log.i("David", "totalPixelsx: "+totalPixelsX);
Log.i("David", "totalPixelsY: "+totalPixelsY);
if(totalPixelsY<0)
Log.i("David", "scroll down");
totalPixelsY=event.getRawY() - startY;
Log.i("David", "We moved "+totalPixelsY+" pixels");
else
Log.i("David", "scroll up");
Log.i("David", "We moved "+totalPixelsY+" pixels");

else
movX=1;
Log.i("David", "Swipe right action cancel");
float totalPixelsX=Math.abs(startX-endX);
float totalPixelsY=event.getRawY() - startY;
Log.i("David", "totalPixelsx: "+totalPixelsX);
Log.i("David", "totalPixelsY: "+totalPixelsY);
if(totalPixelsY<0)
Log.i("David", "scroll down");
totalPixelsY=event.getRawY() - startY;
Log.i("David", "We moved "+totalPixelsY+" pixels");
else
Log.i("David", "scroll up");


Log.i("David", "haveFlipped false");
haveFlipped=false;
break;


return true;

;


My problem is, the action_cancel or action_up are called BEFORE my finger lifts from the phone screen, so the amount of movement in Y axis is always smaller than the actual movement of my finger.



What I plan to achieve is that, when the amount of X > amount of y, use the ViewFlipper, and when the amount of X < amount of y, leave the ScrollView do his job.



I don't know if my approach is correct. Could anyone tell my why action_up and action_cancel are called before I lift my finger? And how to achieve my goal?



Thank you.







android ontouchlistener android-viewflipper






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 7 at 12:05







Fustigador

















asked Mar 7 at 11:57









FustigadorFustigador

3,584113984




3,584113984












  • Try this this it has issues as you seem to have

    – raj kavadia
    Mar 7 at 12:27











  • You should try to inverse the scrollView and the ViewFlipper. A ViewFlipper probably was designed to contain scrollable Views while the ScrollView shouldn't have any scrollable content inside.

    – Maxouille
    Mar 7 at 12:29

















  • Try this this it has issues as you seem to have

    – raj kavadia
    Mar 7 at 12:27











  • You should try to inverse the scrollView and the ViewFlipper. A ViewFlipper probably was designed to contain scrollable Views while the ScrollView shouldn't have any scrollable content inside.

    – Maxouille
    Mar 7 at 12:29
















Try this this it has issues as you seem to have

– raj kavadia
Mar 7 at 12:27





Try this this it has issues as you seem to have

– raj kavadia
Mar 7 at 12:27













You should try to inverse the scrollView and the ViewFlipper. A ViewFlipper probably was designed to contain scrollable Views while the ScrollView shouldn't have any scrollable content inside.

– Maxouille
Mar 7 at 12:29





You should try to inverse the scrollView and the ViewFlipper. A ViewFlipper probably was designed to contain scrollable Views while the ScrollView shouldn't have any scrollable content inside.

– Maxouille
Mar 7 at 12:29












2 Answers
2






active

oldest

votes


















0














If the ViewFlipper returns TRUE at its onTouch() method then the only way is to create a new Class extending RelativeLayout and implements its onInterceptTouchEvent() method.



public class MyRelativeLayout extends RelativeLayout 
@Override
public boolean onInterceptTouchEvent(MotionEvent ev)
return super.onInterceptTouchEvent(ev);




An then use this MyRelativeLayout as root of your XML layout file.






share|improve this answer






























    0














    I managed to get it working by removing this lines from MotionEvent.ACTION_CANCEL and MotionEvent.ACTION_UP:



    endX = event.getX();
    endY = event.getRawY();


    And then, adding this on the switch:



    case MotionEvent.ACTION_MOVE:
    endX = event.getX();
    endY = event.getRawY();
    break;


    This way, both the ScrollView and the ViewFlipper are acting as they should.






    share|improve this answer






















      Your Answer






      StackExchange.ifUsing("editor", function ()
      StackExchange.using("externalEditor", function ()
      StackExchange.using("snippets", function ()
      StackExchange.snippets.init();
      );
      );
      , "code-snippets");

      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "1"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader:
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      ,
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );













      draft saved

      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55043225%2fstruggling-with-ontouchlistener%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      0














      If the ViewFlipper returns TRUE at its onTouch() method then the only way is to create a new Class extending RelativeLayout and implements its onInterceptTouchEvent() method.



      public class MyRelativeLayout extends RelativeLayout 
      @Override
      public boolean onInterceptTouchEvent(MotionEvent ev)
      return super.onInterceptTouchEvent(ev);




      An then use this MyRelativeLayout as root of your XML layout file.






      share|improve this answer



























        0














        If the ViewFlipper returns TRUE at its onTouch() method then the only way is to create a new Class extending RelativeLayout and implements its onInterceptTouchEvent() method.



        public class MyRelativeLayout extends RelativeLayout 
        @Override
        public boolean onInterceptTouchEvent(MotionEvent ev)
        return super.onInterceptTouchEvent(ev);




        An then use this MyRelativeLayout as root of your XML layout file.






        share|improve this answer

























          0












          0








          0







          If the ViewFlipper returns TRUE at its onTouch() method then the only way is to create a new Class extending RelativeLayout and implements its onInterceptTouchEvent() method.



          public class MyRelativeLayout extends RelativeLayout 
          @Override
          public boolean onInterceptTouchEvent(MotionEvent ev)
          return super.onInterceptTouchEvent(ev);




          An then use this MyRelativeLayout as root of your XML layout file.






          share|improve this answer













          If the ViewFlipper returns TRUE at its onTouch() method then the only way is to create a new Class extending RelativeLayout and implements its onInterceptTouchEvent() method.



          public class MyRelativeLayout extends RelativeLayout 
          @Override
          public boolean onInterceptTouchEvent(MotionEvent ev)
          return super.onInterceptTouchEvent(ev);




          An then use this MyRelativeLayout as root of your XML layout file.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 7 at 12:48









          emandtemandt

          1,117259




          1,117259























              0














              I managed to get it working by removing this lines from MotionEvent.ACTION_CANCEL and MotionEvent.ACTION_UP:



              endX = event.getX();
              endY = event.getRawY();


              And then, adding this on the switch:



              case MotionEvent.ACTION_MOVE:
              endX = event.getX();
              endY = event.getRawY();
              break;


              This way, both the ScrollView and the ViewFlipper are acting as they should.






              share|improve this answer



























                0














                I managed to get it working by removing this lines from MotionEvent.ACTION_CANCEL and MotionEvent.ACTION_UP:



                endX = event.getX();
                endY = event.getRawY();


                And then, adding this on the switch:



                case MotionEvent.ACTION_MOVE:
                endX = event.getX();
                endY = event.getRawY();
                break;


                This way, both the ScrollView and the ViewFlipper are acting as they should.






                share|improve this answer

























                  0












                  0








                  0







                  I managed to get it working by removing this lines from MotionEvent.ACTION_CANCEL and MotionEvent.ACTION_UP:



                  endX = event.getX();
                  endY = event.getRawY();


                  And then, adding this on the switch:



                  case MotionEvent.ACTION_MOVE:
                  endX = event.getX();
                  endY = event.getRawY();
                  break;


                  This way, both the ScrollView and the ViewFlipper are acting as they should.






                  share|improve this answer













                  I managed to get it working by removing this lines from MotionEvent.ACTION_CANCEL and MotionEvent.ACTION_UP:



                  endX = event.getX();
                  endY = event.getRawY();


                  And then, adding this on the switch:



                  case MotionEvent.ACTION_MOVE:
                  endX = event.getX();
                  endY = event.getRawY();
                  break;


                  This way, both the ScrollView and the ViewFlipper are acting as they should.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Mar 7 at 13:06









                  FustigadorFustigador

                  3,584113984




                  3,584113984



























                      draft saved

                      draft discarded
















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid


                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.

                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55043225%2fstruggling-with-ontouchlistener%23new-answer', 'question_page');

                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Save data to MySQL database using ExtJS and PHP [closed]2019 Community Moderator ElectionHow can I prevent SQL injection in PHP?Which MySQL data type to use for storing boolean valuesPHP: Delete an element from an arrayHow do I connect to a MySQL Database in Python?Should I use the datetime or timestamp data type in MySQL?How to get a list of MySQL user accountsHow Do You Parse and Process HTML/XML in PHP?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?Why shouldn't I use mysql_* functions in PHP?

                      Compiling GNU Global with universal-ctags support Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Tags for Emacs: Relationship between etags, ebrowse, cscope, GNU Global and exuberant ctagsVim and Ctags tips and trickscscope or ctags why choose one over the other?scons and ctagsctags cannot open option file “.ctags”Adding tag scopes in universal-ctagsShould I use Universal-ctags?Universal ctags on WindowsHow do I install GNU Global with universal ctags support using Homebrew?Universal ctags with emacsHow to highlight ctags generated by Universal Ctags in Vim?

                      Add ONERROR event to image from jsp tldHow to add an image to a JPanel?Saving image from PHP URLHTML img scalingCheck if an image is loaded (no errors) with jQueryHow to force an <img> to take up width, even if the image is not loadedHow do I populate hidden form field with a value set in Spring ControllerStyling Raw elements Generated from JSP tagds with Jquery MobileLimit resizing of images with explicitly set width and height attributeserror TLD use in a jsp fileJsp tld files cannot be resolved