Android Put animation in Page scroll in view pager using fragment(Android使用片段在视图寻呼机中的页面滚动中放置动画)
问题描述
我想在视图寻呼机中滚动页面时放置动画(放大缩小、淡入淡出、3d 等).我的代码如下.
I want to put animation(zoom in-out,fade in-out,3d etc) when page scroll in view pager. my code is the following.
我的第一堂课:
public class ViewPagerMainActivity extends FragmentActivity implements
OnClickListener, OnPageChangeListener {
// all variable declare here
@SuppressLint("NewApi")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(
WindowManager.LayoutParams.FLAG_FULLSCREEN
| WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD,
WindowManager.LayoutParams.FLAG_FULLSCREEN
| WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
);
setTheme(android.R.style.Theme_Light_NoTitleBar);
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
}
}
@Override
public void onClick(View v) {
}
@Override
public void onPageScrollStateChanged(int arg0) {
// TODO Auto-generated method stub
}
@Override
public void onPageScrolled(int arg0, float arg1, int arg2) {
// TODO Auto-generated method stub
}
@Override
public void onPageSelected(int arg0) {
// TODO Auto-generated method stub
}
@Override
public void onBackPressed() {
}
}
第二个文件:
public class FirstFragment extends Fragment implements OnTouchListener {
// all variable decalre here
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
getActivity().setTheme(android.R.style.Theme_Light_NoTitleBar);
v = inflater.inflate(R.layout.sliding_lock_pager, container, false);
// other code here
return v;
}
public static FirstFragment newInstance(String text) {
FirstFragment f = new FirstFragment();
Bundle b = new Bundle();
b.putString("msg", text);
f.setArguments(b);
return f;
}
@Override
public boolean onTouch(View v, MotionEvent event) {
return false;
}
这里是第三个文件:
public class SecondFragment extends Fragment implements OnClickListener {
// all varible decalare here
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
getActivity().setTheme(android.R.style.Theme_Light_NoTitleBar);
View v = inflater.inflate(R.layout.password, container, false);
// other code here
// this method move to main pager
txtBack.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
((ViewPagerMainActivity)getActivity()).pager.setCurrentItem(0);
}
});
return v;
}
public static SecondFragment newInstance(String text) {
SecondFragment f = new SecondFragment();
Bundle b = new Bundle();
b.putString("msg", text);
f.setArguments(b);
return f;
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
我想在寻呼机滚动或调用 ((ViewPagerMainActivity)getActivity()).pager.setCurrentItem(0);
时放置动画,当寻呼机滚动下一页时会显示类似缩放的动画-请任何人帮助我如何做到这一点.
I want to put animation when pager scroll or call ((ViewPagerMainActivity)getActivity()).pager.setCurrentItem(0);
at that time when pager scroll next page display with animation like zoomin-out please any one help me to how to do this one.
推荐答案
您可以将 PagerTransformer 附加到 ViewPager :
You can attach PagerTransformer to 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#pagetransformer
http://andraskindler.com/blog/2013/create-viewpager-transitions-a-pagertransformer-example/
这篇关于Android使用片段在视图寻呼机中的页面滚动中放置动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Android使用片段在视图寻呼机中的页面滚动中放置动画
基础教程推荐
- Android:对话框关闭而不调用关闭 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01