Advertisement
Guest User

Untitled

a guest
Feb 8th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:orientation="vertical"
  4. android:layout_width="match_parent"
  5. android:layout_height="match_parent">
  6. <android.support.v4.view.ViewPager
  7. android:id="@+id/viewpager"
  8. android:gravity="center"
  9. android:layout_width="match_parent"
  10. android:layout_height="wrap_content"
  11. android:clipToPadding="false" />
  12. </LinearLayout>
  13.  
  14. private const float MIN_SCALE = 0.85f;
  15. private const float MIN_ALPHA = 0.5f;
  16. public void TransformPage(View page, float position)
  17. {
  18. int pageWidth = page.Width;
  19. int pageHeight = page.Height;
  20.  
  21. if (position < -1)
  22. {
  23. // [-Infinity,-1)
  24. // This page is way off-screen to the left.
  25. page.Alpha = 0;
  26. Console.WriteLine("1.Position: " + position);
  27. }
  28. else if (position <= 1)
  29. {
  30. // [-1,1]
  31. // Modify the default slide transition to shrink the page as well
  32. float scaleFactor = Math.Max(MIN_SCALE, 1 - Math.Abs(position));
  33. float vertMargin = pageHeight * (1 - scaleFactor) / 2;
  34. float horzMargin = pageWidth * (1 - scaleFactor) / 2;
  35. if (position < 0)
  36. {
  37. page.TranslationX = (horzMargin - vertMargin / 2);
  38. }
  39. else {
  40. page.TranslationX = (-horzMargin + vertMargin / 2);
  41. }
  42.  
  43. // Scale the page down (between MIN_SCALE and 1)
  44. page.ScaleX=(scaleFactor);
  45. page.ScaleY=(scaleFactor);
  46.  
  47. // Fade the page relative to its size.
  48. page.Alpha = (MIN_ALPHA + (scaleFactor - MIN_SCALE) / (1 - MIN_SCALE) * (1 - MIN_ALPHA));
  49. Console.WriteLine("2.Position: " + position);
  50. }
  51. else {
  52. // (1,+Infinity]
  53. // This page is way off-screen to the right.
  54. page.Alpha = 0;
  55. Console.WriteLine("3.Position: " + position);
  56. }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement