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

Apple's genius hacker opens source software for autonomous driving

At the end of October, according to foreign media...

I didn’t spend a penny on promotion and achieved 23 million app downloads!

The author of this article spent 6 hours to creat...

An experiment that you can't even bear to read, but he cruelly did several

The college entrance examination is an important ...

HTC U Ultra new flagship battery life test: better than Samsung S7

HTC's new flagship U Ultra adopts a mirror edg...

Year-end review: Major breakthroughs in Chinese science and technology in 2021

2021 is coming to an end. The past year has been ...

7 tips and analysis methods for ToB content operations!

This article analyzes competitors from three pers...

How to design an efficient check-in activity? Here are 4 tips

Many APP operators will encounter the following t...

What’s new in iOS 13.4 beta 2?

Apple launched the second developer beta of iOS/i...