Android ViewPager 具有不同的动画,如放大、淡入淡出等
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23129847/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Android ViewPager With different Animation like zoom in,fade etc
提问by Nirav Mehta
I have created ViewPager ,there are only 2 page are there,I want to put animation like fade in,scale,zoom,3d etc when pager scroll one page to another second one,means second entire page display with specific animation , I have no idea to how to do this,please any one give me a some example of put animation when move to another page that time we animate pager.
我创建了 ViewPager ,那里只有 2 页,我想在寻呼机将一页滚动到另一页时添加淡入、缩放、缩放、3d 等动画,这意味着第二个整个页面显示具有特定动画,我没有关于如何做到这一点的想法,请任何人给我一些当我们为寻呼机设置动画时移动到另一个页面时放置动画的示例。
Mainly I have three class for pager :1) ViewPagerMainActivity : it call two fragment that is swipe in this main look like enter code here
主要是我有三个用于寻呼机的类:1)ViewPagerMainActivity:它调用两个在这个主要看起来像滑动的片段 enter code here
public class ViewPagerMainActivity extends FragmentActivity implements
OnClickListener, OnPageChangeListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.view_pager_main);
<other code here>
}
private class MyPagerAdapter extends FragmentPagerAdapter {
public MyPagerAdapter(
android.support.v4.app.FragmentManager fragmentManager) {
super(fragmentManager);
}
@Override
public Fragment getItem(int pos) {
switch (pos) {
case 0:
return FirstFragment.newInstance("");
case 1:
return SecondFragment.newInstance("");
default:
return SecondFragment.newInstance("Default");
}
}
@Override
public int getCount() {
return 2; // return no of fragment created by us
}
}
}
}
In first fragment containing swipe design and second fragment contains second xml file design when I swipe first fragment to another at that time I want to put animation. means while swiping it display any one animation effect choose from different animation option. how to I create animation and where to put this in it. please help quickly thanks in advance.
在包含滑动设计的第一个片段中,当我将第一个片段滑动到另一个片段时,第二个片段包含第二个 xml 文件设计,当时我想放置动画。意味着在滑动它时显示从不同动画选项中选择的任何一种动画效果。如何创建动画以及将其放入何处。请快速帮助提前致谢。
回答by
You can attach PagerTransformer to ViewPager :
您可以将 PagerTransformer 附加到 ViewPager :
mViewPager.setPageTransformer(false, new ViewPager.PageTransformer() {
@Override
public void transformPage(View page, float position) {
// do transformation here
}
});
You can go through following links which will help you :
您可以通过以下链接来帮助您:
http://developer.android.com/training/animation/screen-slide.html#pagetransformeror http://andraskindler.com/blog/2013/create-viewpager-transitions-a-pagertransformer-example/
http://developer.android.com/training/animation/screen-slide.html#pagetransformer或 http://andraskindler.com/blog/2013/create-viewpager-transitions-a-pagertransformer-example/