Make an animation like changing a page while scrolling

I have an application for which I am using SimpleGestureFilter.java, and what it does calls the right function when scrolling (left right double tap ... etc), here is a piece of code

@Override public boolean dispatchTouchEvent(MotionEvent me){ // Call onTouchEvent of SimpleGestureFilter class this.detector.onTouchEvent(me); return super.dispatchTouchEvent(me); } public void onSwipe(int direction) { String str = ""; switch (direction) { case SimpleGestureFilter.SWIPE_RIGHT : minusOne(); str = "Swipe Right"; break; case SimpleGestureFilter.SWIPE_LEFT : plusOne(); str = "Swipe Left"; break; } } 

So what I want to do when plusOne () is configured or some other functions it does something, and it sends the intention to the same MainActivity.java class, I try to achieve when this event will look like a book slide of a page, to have somesort transitions between altought screens this is only one MainActivity screen

  Intent i = new Intent(this,MainActivity.class); i.putExtra(DBAdapter.KEY_pk_ymd, Integer.parseInt(dt)); startActivityForResult(i,ACTIVITY_EDIT); 
+3
source share
2 answers

use: push_left_in.xml

  <?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/accelerate_interpolator"> <translate android:fromXDelta="100%p" android:toXDelta="0" android:duration="300"/> <alpha android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="300" /> 

and push_left_out.xml

 <?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/accelerate_interpolator"> <translate android:fromXDelta="0" android:toXDelta="-100%p" android:duration="300"/> <alpha android:fromAlpha="1.0" android:toAlpha="0.0" android:duration="300" /> </set> 

all xml are in res / anim and are called such

  Intent i = new Intent(this,MainActivity.class); startActivityForResult(i,ACTIVITY_EDIT); overridePendingTransition(R.anim.push_left_in,R.anim.push_left_out); 
+4
source

This google code can be used here:

https://code.google.com/p/android-3d-flip-view-transition

Once it is imported, you simply use:

 AnimationFactory.flipTransition(viewFlipper, FlipDirection.LEFT_RIGHT); 

And you feel good, just an efficient library.

EDIT:

Another option is to include an animated call in your intentions, but turning the page would be difficult for that. A simple style animation or scroll in style can be implemented:

overridePendingTransition (int enterAnim, int exitAnim)

 push_right_in.xml <?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <translate android:fromXDelta="-100%p" android:toXDelta="0" android:duration="@android:integer/config_shortAnimTime"/> <alpha android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="@android:integer/config_shortAnimTime" /> </set> push_right_out.xml <?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <translate android:fromXDelta="0" android:toXDelta="100%p" android:duration="@android:integer/config_shortAnimTime"/> <alpha android:fromAlpha="1.0" android:toAlpha="0.0" android:duration="@android:integer/config_shortAnimTime" /> </set> 

Is it closer to what you need? The library that I posted in the first answer is very easy to use and gives a good effect.

+1
source

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


All Articles