答案 0 :(得分:1)
您应该将ViewPager与Viewpager.PageTransformer一起使用,在这里您可以找到示例:https://github.com/geftimov/android-viewpager-transformers
您必须使用否定的pagemargin才能看到左侧和右侧。 (https://developer.android.com/reference/android/support/v4/view/ViewPager.html#setPageMargin(int))
这是Xamarin Android中PageTransformer的代码,您可以快速修改它以在原生Android上使用它。创建一个ViewPager_Transform_CenterBig对象并使用yourViewpager.setPageTransformer(false, new ViewPager_Transform_CenterBig(0.90f))
;设置变压器
public class ViewPager_Transform_CenterBig: Java.Lang.Object, ViewPager.IPageTransformer
{
public float Scale {
get;
private set;
}
public ViewPager_Transform_CenterBig (float scale)
{
Scale = scale;
}
#region IPageTransformer implementation
public void TransformPage (Android.Views.View page, float position)
{
int pageWidth = page.Width;
int pageHeight = page.Height;
if (position <= 1) {
// [-1,1]
// Modify the default slide transition to shrink the page as well
float scaleFactor = Math.Max (Scale, 1 - Math.Abs (position)* 0.3f);
float vertMargin = pageHeight * (1 - scaleFactor) * 0.5f;
float horzMargin = pageWidth * (1 - scaleFactor) * 0.5f;
page.TranslationX = position < 0
? (horzMargin - vertMargin * 0.5f)
: (-horzMargin + vertMargin * 0.5f);
// Scale the page down (between MIN_SCALE and 1)
page.ScaleX = (scaleFactor);
page.ScaleY = (scaleFactor);
}
}
#endregion
}