Android - Show/Hide TextView using Swipe Left to Right

wdyz

I'm trying to show/hide TextView. So if the user swipe left-to-right, it will show TextView from behind the "orange gradient view". And after the text shown, after 5 seconds, it will hiding it again like the picture below:

Swipe left-to-right to show TextView

But i don't have any idea what the best practice to implement just like above. Please help.

Pranav Darji

Here is the xml file

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/activity_theme_sel_ll_main"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

   <!--Add your content here for texview and whatever -->
    </LinearLayout>

Now use this class

import android.content.Context;
import android.view.GestureDetector;
import android.view.GestureDetector.SimpleOnGestureListener;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;

/**
 * This TouchListener is Using for very First time ThemeSelection Screen with SwipeLeft Finger
 */
public class OnSwipeTouchListener implements OnTouchListener {

    private final GestureDetector gestureDetector;

    public OnSwipeTouchListener(Context ctx) {
        gestureDetector = new GestureDetector(ctx, new GestureListener());
    }

    @Override
    public boolean onTouch(View v, MotionEvent event) {
        return gestureDetector.onTouchEvent(event);
    }

    private final class GestureListener extends SimpleOnGestureListener {

        private static final int SWIPE_THRESHOLD = 1;
        private static final int SWIPE_VELOCITY_THRESHOLD = 1;

        @Override
        public boolean onDown(MotionEvent e) {
            return true;
        }

        @Override
        public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
            boolean result = false;
            try {
                float diffY = e2.getY() - e1.getY();
                float diffX = e2.getX() - e1.getX();
                if (Math.abs(diffX) > Math.abs(diffY)) {
                    if (Math.abs(diffX) > SWIPE_THRESHOLD && Math.abs(velocityX) > SWIPE_VELOCITY_THRESHOLD) {
                        if (diffX > 0) {
                            onSwipeRight();
                        } else {
                            onSwipeLeft();
                        }
                    }
                    result = true;
                } else if (Math.abs(diffY) > SWIPE_THRESHOLD && Math.abs(velocityY) > SWIPE_VELOCITY_THRESHOLD) {
                    if (diffY > 0) {
                        onSwipeBottom();
                    } else {
                        onSwipeTop();
                    }
                }
                result = true;

            } catch (Exception exception) {
                exception.printStackTrace();
            }
            return result;
        }
    }

    public void onSwipeRight() {
    }

    public void onSwipeLeft() {
    }

    public void onSwipeTop() {
    }

    public void onSwipeBottom() {
    }
}

In your MainActivity.java class use below code

//llMain is the root layout of your xml where you want to perform swipe 
        llMain.setOnTouchListener(new OnSwipeTouchListener(ThemeSelectionActivity.this) {
            @Override
            public void onSwipeLeft() {
                super.onSwipeLeft();

                }
            }

            @Override
            public void onSwipeRight() {
                super.onSwipeRight();

    // Put your logic here for text visibility and for timer like progress bar for 5 second and setText 
            }
        });

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

Android: How to handle right to left swipe gestures

From Dev

How to prevent vertical scroll on swipe left/right

From Dev

Swipe animation from left to right infinite time

From Dev

UIPageViewControllerDatasource calling both swipe left and swipe right methods

From Dev

Animating text from left to right trims text in TextView Android

From Dev

Translate TextView from Right to Left

From Dev

How to animate left/right swipe view using UISwipeGestureRecognizer

From Dev

Polymer swipe left or right to show new page

From Dev

Swipe left and right in scrollView

From Dev

swipe left or right in windows phone 8.1

From Dev

How to apply color transition for textview from left to right android?

From Dev

Xamarin Forms Swipe Left/Swipe Right Gestures

From Dev

Android ListView Swipe Right and Left to Accept and Reject

From Dev

Issue with Left to Right Swipe Gesture in Android

From Dev

i want to swipe right and left in swift

From Dev

How implement left/ right swipe/fling on layout in android

From Dev

rotate image while swipe is in progress using angular ng-swipe-left and ng-swipe-right

From Dev

Swipe left right for poll

From Dev

Determine whether a swipe event is for a left swipe or a right swipe

From Dev

Tabs Swipe direction in Right to Left Android app

From Dev

How to restrict ItemtouchHelper to swipe only left to right

From Dev

android animation textview rotate string left to right

From Dev

How to implement left to right swipe between screens

From Dev

Android textview swipe with ArrayAdapter

From Dev

Translate TextView from Right to Left

From Dev

Swipe imageview left and right in android

From Dev

i want to swipe right and left in swift

From Dev

Moving player in Subway Surf like game using left/right swipe

From Dev

Stack Float the TextView in Left and Right

Related Related

  1. 1

    Android: How to handle right to left swipe gestures

  2. 2

    How to prevent vertical scroll on swipe left/right

  3. 3

    Swipe animation from left to right infinite time

  4. 4

    UIPageViewControllerDatasource calling both swipe left and swipe right methods

  5. 5

    Animating text from left to right trims text in TextView Android

  6. 6

    Translate TextView from Right to Left

  7. 7

    How to animate left/right swipe view using UISwipeGestureRecognizer

  8. 8

    Polymer swipe left or right to show new page

  9. 9

    Swipe left and right in scrollView

  10. 10

    swipe left or right in windows phone 8.1

  11. 11

    How to apply color transition for textview from left to right android?

  12. 12

    Xamarin Forms Swipe Left/Swipe Right Gestures

  13. 13

    Android ListView Swipe Right and Left to Accept and Reject

  14. 14

    Issue with Left to Right Swipe Gesture in Android

  15. 15

    i want to swipe right and left in swift

  16. 16

    How implement left/ right swipe/fling on layout in android

  17. 17

    rotate image while swipe is in progress using angular ng-swipe-left and ng-swipe-right

  18. 18

    Swipe left right for poll

  19. 19

    Determine whether a swipe event is for a left swipe or a right swipe

  20. 20

    Tabs Swipe direction in Right to Left Android app

  21. 21

    How to restrict ItemtouchHelper to swipe only left to right

  22. 22

    android animation textview rotate string left to right

  23. 23

    How to implement left to right swipe between screens

  24. 24

    Android textview swipe with ArrayAdapter

  25. 25

    Translate TextView from Right to Left

  26. 26

    Swipe imageview left and right in android

  27. 27

    i want to swipe right and left in swift

  28. 28

    Moving player in Subway Surf like game using left/right swipe

  29. 29

    Stack Float the TextView in Left and Right

HotTag

Archive