3D parallax guide page

3D parallax guide page

Source code introduction: 3D parallax guide page, sub-control translation, zooming, 3D flipping when ViewPager slides

Source code effect:

Source code snippet:

  1. /**
  2. * When our ViewPager slides, each page will call back this method
  3. * position: the current page
  4. * view: the view corresponding to a page --- the layout view
  5. */  
  6. @Override  
  7. public   void transformPage(View view, float position) {
  8. // Gradient effect, judgment interval (-1, 1)  
  9. if (position< 1 && position >- 1 ) {
  10. // Parallax acceleration effect, giving all subspaces inside an acceleration offset  
  11. ViewGroup rl=(ViewGroup) view.findViewById(R.id.rl);
  12. // for (int i = 0; i < rl.getChildCount(); i++) {  
  13. // View child=rl.getChildAt(i);  
  14. // float factoe=(float) (Math.random()*2);  
  15. // if (child.getTag() == null) {  
  16. // child.setTag(factoe);  
  17. // }else{  
  18. // factoe=(Float) child.getTag();  
  19. // }  
  20. // // Acceleration offset (add an offset value to the child's original position)  
  21. // child.setTranslationX(-position*200*factoe);  
  22. // child.setTranslationY(position*100*factoe);  
  23. // }  
  24. // Zoom effect  
  25. // Scaling range: 0-1  
  26. rl.setScaleX(Math.max( 0 .8f, 1 -Math.abs(position)));
  27. rl.setScaleY(Math.max( 0 .8f, 1 -Math.abs(position)));
  28.               
  29. // 3D flip animation flips outward  
  30. // rl.setPivotX(position<0f?rl.getWidth():0f);  
  31. // rl.setPivotY(rl.getHeight()*0.5f);  
  32. // rl.setRotationY(position*90);  
  33.               
  34. // 3D flip animation flips inward  
  35. // rl.setPivotX(position<0f?rl.getWidth():0f);  
  36. // rl.setPivotY(rl.getHeight()*0.5f);  
  37. // rl.setRotationY(-position*90);  
  38.               
  39. // Mutton kebab effect  
  40. rl.setPivotX(rl.getHeight()* 0.5f );
  41. rl.setPivotY(rl.getHeight()* 0.5f );
  42. rl.setRotationY(-position* 90 );
  43. }
  44. }

Download address: http://download..com/data/2091673

<<:  The development of China's mobile game industry has grown sixfold in four years. What problems still exist?

>>:  QQ space stretchable head

Recommend

Remember to look up recently! This life-threatening journey is about to begin

I am a bird-watching enthusiast. However, sometim...

I can’t bear to throw away expired food, but can I still eat it?

I found out that the food I wanted to eat has exp...

A guide to avoiding pitfalls for new consumer brands in 2022

The "excitement" of new consumption has...

Can O2O in the beauty industry revolutionize female consumption?

The life service industry is being changed by O2O...

How to write a beautiful DSL using Objective-C

Foreword: This article is contributed by Zang Che...

3 things you didn't know about the MacBook Air's demise

Back in 2010, Apple launched a new version of the...