Android Viewpager animation effects

Source: Internet
Author: User

  1. Package com.example.jaazy;
  2. Import java.util.ArrayList;
  3. Import Android.support.v4.view.PagerAdapter;
  4. Import Android.view.View;
  5. Import Android.view.View.OnClickListener;
  6. Import Android.view.ViewGroup;
  7. /**
  8. * Create by Lanyan on 2014.04.24
  9. * This is a adapter
  10. */
  11. Public class Viewpageradapteronclick extends Pageradapter {
  12. private arraylist<view> views;
  13. private Viewpageonclick callback;
  14. Private Jazzyviewpager Pager;
  15. Public Viewpageradapteronclick (Jazzyviewpager pager,arraylist<view> Views,viewpageonclick callback) {
  16. this.setviews (views);
  17. This.callback=callback;
  18. This.pager=pager;
  19. }
  20. public void Setviews (arraylist<view> views) {
  21. if (views! = null)
  22. this.views = views;
  23. Else
  24. this.views = new arraylist<view> ();
  25. }
  26. public void Changeitem (arraylist<view> views) {
  27. this.setviews (views);
  28. Notifydatasetchanged ();
  29. }
  30. @Override
  31. public int GetItemPosition (Object object) {
  32. //TODO auto-generated method stub
  33. return position_none;
  34. }
  35. @Override
  36. public int GetCount () {
  37. //TODO auto-generated method stub
  38. return views.size ();
  39. }
  40. @Override
  41. Public Boolean isviewfromobject (View arg0, Object arg1) {
  42. //TODO auto-generated method stub
  43. return arg0 = = Arg1;
  44. }
  45. @Override
  46. public void Destroyitem (ViewGroup container, int position, Object object) {
  47. View v = views.get (position);
  48. Container.removeview (v);
  49. }
  50. public void Removeupdate (ViewGroup container) {
  51. Container.removeallviews ();
  52. }
  53. @Override
  54. Public Object Instantiateitem (ViewGroup container, final int position) {
  55. View v = views.get (position);
  56. V.setonclicklistener (new Onclicklistener () {
  57. public void OnClick (View v) {
  58. //TODO auto-generated method stub
  59. Callback.callbackonclickitem (position);
  60. }
  61. });
  62. Container.addview (v);
  63. Pager.setobjectforposition (v, position);
  64. return v;
  65. }
  66. public interface viewpageonclick{
  67. void Callbackonclickitem (int position);
  68. }
  69. }

Activity

[Java]View Plaincopy
  1. Import java.util.ArrayList;
  2. Import android.app.Activity;
  3. Import Android.os.Bundle;
  4. Import Android.view.View;
  5. Import Android.view.ViewGroup.LayoutParams;
  6. Import Android.widget.ImageView;
  7. Import Android.widget.Toast;
  8. Import Com.example.jaazy.JazzyViewPager.TransitionEffect;
  9. Import Com.example.jaazy.ViewPagerAdapterOnClick.ViewPageOnClick;
  10. Public class Mainactivity extends Activity implements viewpageonclick{
  11. Private Jazzyviewpager Pager;
  12. private Viewpageradapteronclick adapter;
  13. @Override
  14. protected void OnCreate (Bundle savedinstancestate) {
  15. super.oncreate (savedinstancestate);
  16. Setcontentview (R.layout.activity_main);
  17. Setupjazziness (Transitioneffect.stack);
  18. }
  19. private void setupjazziness (TransitionEffect stack) {
  20. //TODO auto-generated method stub
  21. Pager= (Jazzyviewpager) Findviewbyid (R.id.jazzy_pager);
  22. adapter=New Viewpageradapteronclick (pager, getviews (), this);
  23. Pager.setadapter (adapter);
  24. Pager.setpagemargin (5);
  25. //Press Stack mode
  26. Pager.settransitioneffect (Transitioneffect.stack);
  27. //Stereo internal access
  28. //pager.settransitioneffect (Transitioneffect.cubein);
  29. //Stereoscopic projection
  30. //pager.settransitioneffect (transitioneffect.cubeout);
  31. //Left /Right Extrusion
  32. //pager.settransitioneffect (transitioneffect.accordion);
  33. //Horizontal page
  34. //pager.settransitioneffect (transitioneffect.fliphorizontal);
  35. //Vertical page
  36. //pager.settransitioneffect (transitioneffect.flipvertical);
  37. //fan-in swing
  38. //pager.settransitioneffect (Transitioneffect.rotatedown);
  39. //Bottom sector swing in
  40. //pager.settransitioneffect (transitioneffect.rotateup);
  41. //Standard
  42. //pager.settransitioneffect (Transitioneffect.standard);
  43. //tabs (Card form)
  44. ///pager.settransitioneffect (Transitioneffect.tablet);
  45. //zoom in
  46. //pager.settransitioneffect (transitioneffect.zoomin);
  47. //zoom out
  48. //pager.settransitioneffect (transitioneffect.zoomout);
  49. }
  50. private arraylist<view> Getviews () {
  51. //TODO auto-generated method stub
  52. arraylist<view> list=New arraylist<view> ();
  53. ImageView i=New ImageView (this);
  54. Layoutparams params=New Layoutparams (Layoutparams.match_parent, layoutparams.match_parent);
  55. I.setlayoutparams (params);
  56. I.setbackgroundresource (R.DRAWABLE.A);
  57. ImageView i2=New ImageView (this);
  58. I2.setlayoutparams (params);
  59. I2.setbackgroundresource (r.drawable.b);
  60. ImageView i3=New ImageView (this);
  61. I3.setlayoutparams (params);
  62. I3.setbackgroundresource (R.DRAWABLE.C);
  63. ImageView i4=New ImageView (this);
  64. I4.setlayoutparams (params);
  65. I4.setbackgroundresource (R.DRAWABLE.E);
  66. List.add (i);
  67. List.add (I2);
  68. List.add (i3);
  69. List.add (I4);
  70. return list;
  71. }
  72. @Override
  73. public void Callbackonclickitem (int position) {
  74. //TODO auto-generated method stub
  75. Toast.maketext (This, "position:" +position, + ). Show ();
  76. }
  77. }

Jazzyviewpager the animated enumeration 11, if you need other animations, you can add it yourself

Android Viewpager animation effects

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.