Modify the ViewPager switching animation effect, and change the viewpager switching Animation

Source: Internet
Author: User

Modify the ViewPager switching animation effect, and change the viewpager switching Animation

For example, if we click the right button and want to move the view on the left to have a translation effect, the system will flash when switching with the default ViewPager. Why?

Because viewpager actually has a scrollview, you can use the reflection method to set its scroll time. The Code is as follows.

Main Code:

// Step 1:

LayoutInflater mInflater = (LayoutInflater) context. getSystemService (Context. LAYOUT_INFLATER_SERVICE); View view = mInflater. from (context ). inflate (R. layout. vw_personalcyclic gtarget_test, personalFileMain); MyCycTargetViewPager mVp = (MyCycTargetViewPager) view. findViewById (R. id. cyctarget_viewpager); try {// viePager translation animation event Field mField = ViewPager. class. getDeclaredField ("mScroller"); mField. setAccessible (true); MyScroller mScroller = new MyScroller (mVp. getContext (), new AccelerateInterpolator (); mField. set (mVp, mScroller);} catch (NoSuchFieldException e) {e. printStackTrace ();} catch (IllegalArgumentException e) {e. printStackTrace ();} catch (IllegalAccessException e) {e. printStackTrace ();}
// Step 2:

/***** @ Desc: ViewPager animation time * @ author: pangzf * @ date: august 13, 2014 6:00:05 */public class MyScroller extends Scroller {// set the translation time you need private int animTime = 500; public MyScroller (Context context) {super (context );} public MyScroller (Context context, Interpolator interpolator) {super (context, interpolator) ;}@ Override public void startScroll (int startX, int startY, int dx, int dy, int duration) {super. startScroll (startX, startY, dx, dy, animTime) ;}@ Override public void startScroll (int startX, int startY, int dx, int dy) {super. startScroll (startX, startY, dx, dy, animTime);} public void setmDuration (int animTime) {this. animTime = animTime ;}
You cannot use viewpager to slide left or right in our project. You can click link to disable the sliding left or right.

Click the right button:




How can I remove the ViewPager switching animation or custom switching animation?

Let's see if you want anything? Search.eoeandroid.com/..t?true=you can search again in the Forum. There will be new discoveries.
 
How to remove the Viewpager switching animation?

Now I have made an application. Viewpager is very tangled. I have four screens, and there is no problem with sliding left and right. However, from the first screen to the fourth screen, the screen will go through 2 or 3 in the middle, and the interface looks ugly, how can we not execute this animation and look forward to a solution.
 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.