Tap scroll in Flipper view in Android?

I need to achieve this Touch scroll on ViewFlipper. For instance. I have two images. Firstly, ViewFlipper shows the first image. Now I glance from right to left. First view of the image Slide left and the second slide to the left. I can achieve this. Message But I want to scroll the image. That is, in the Action_Move event, I want to make a Touch Scroll. For example, when I move the touch from right to left, it throws all the touch movements. at this time, both images should be output.

How to do it? What do I need to measure screen levels (height and width). Code examples are more useful.

+4
source share
2 answers
package com.appaapps.flipper; import android.app.Activity; import android.content.Context; import android.graphics.*; import android.os.Bundle; import android.view.MotionEvent; import android.view.View; import android.widget.ViewFlipper; //------------------------------------------------------------------------------ // Flipper - Philip R Brenan at gmail.com //------------------------------------------------------------------------------ public class FlipperActivity extends Activity { ViewFlipper f; DrawView a, b, c; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); f = new ViewFlipper(this); a = new DrawView(this, "aaaaa"); b = new DrawView(this, "BBBBB"); c = new DrawView(this, "ccccc"); f.addView(a); f.addView(b); f.addView(c); setContentView(f); } //------------------------------------------------------------------------------ // Draw //------------------------------------------------------------------------------ class DrawView extends View implements View.OnTouchListener { final String text; DrawView(Context Context, String Text) { super(Context); text = Text; setOnTouchListener(this); } public void onDraw(Canvas Canvas) { super.onDraw(Canvas); Paint p = new Paint(); p.setColor(0xffffffff); p.setTextSize(20); Canvas.drawText(text, 0, 20, p); } public boolean onTouch(View v, MotionEvent event) { final int a = event.getAction(); if (a == MotionEvent.ACTION_DOWN) { final int i = f.getDisplayedChild(), n = f.getChildCount(); f.setDisplayedChild((i + 1) % n); } return true; } } } 
+1
source

If you need to detect scrolling only in a view mode that does not occupy the entire screen, try below

 gestureDetector = new GestureDetector(new MyGestureDetector()); viewFlipper.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (gestureDetector.onTouchEvent(event)) { return false; } return true; } }); 

and MyGestureDetector will be the same as in http://www.codeshogun.com/blog/2009/04/16/how-to-implement-swipe-action-in-android/

0
source

Source: https://habr.com/ru/post/1315052/


All Articles