Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical"
- android:layout_width="match_parent"
- android:layout_height="match_parent">
- <android.support.v4.view.ViewPager
- android:id="@+id/viewpager"
- android:gravity="center"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:clipToPadding="false" />
- </LinearLayout>
- private const float MIN_SCALE = 0.85f;
- private const float MIN_ALPHA = 0.5f;
- public void TransformPage(View page, float position)
- {
- int pageWidth = page.Width;
- int pageHeight = page.Height;
- if (position < -1)
- {
- // [-Infinity,-1)
- // This page is way off-screen to the left.
- page.Alpha = 0;
- Console.WriteLine("1.Position: " + position);
- }
- else if (position <= 1)
- {
- // [-1,1]
- // Modify the default slide transition to shrink the page as well
- float scaleFactor = Math.Max(MIN_SCALE, 1 - Math.Abs(position));
- float vertMargin = pageHeight * (1 - scaleFactor) / 2;
- float horzMargin = pageWidth * (1 - scaleFactor) / 2;
- if (position < 0)
- {
- page.TranslationX = (horzMargin - vertMargin / 2);
- }
- else {
- page.TranslationX = (-horzMargin + vertMargin / 2);
- }
- // Scale the page down (between MIN_SCALE and 1)
- page.ScaleX=(scaleFactor);
- page.ScaleY=(scaleFactor);
- // Fade the page relative to its size.
- page.Alpha = (MIN_ALPHA + (scaleFactor - MIN_SCALE) / (1 - MIN_SCALE) * (1 - MIN_ALPHA));
- Console.WriteLine("2.Position: " + position);
- }
- else {
- // (1,+Infinity]
- // This page is way off-screen to the right.
- page.Alpha = 0;
- Console.WriteLine("3.Position: " + position);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement