Android ViewPager with ImageViews -


i have viewpager houses 4 frame layouts each different image background. have tried several ways of loading , resizing images viewpager still laggy when swipe; since has change background images accordingly.

other apps such quizup , of google's own apps have images on tutorial , they're smooth. there way achieve same effect; keep images backgrounds while optimizing viewpager's performance?

here viewpager adapter;

private class screenslidepageradapter extends pageradapter {      context context;     layoutinflater layoutinflater;      public screenslidepageradapter(context context) {         this.context = context;     }      @override     public int getcount() {         return num_pages;     }      @override     public boolean isviewfromobject(view view, object object) {         return view == object;     }      @override     public object instantiateitem(viewgroup container, int position) {         textview text1 = null, text2 = null, text3 = null, text4 = null;         imageview background;         button begin;          layoutinflater = (layoutinflater) context.getsystemservice(context.layout_inflater_service);         view layout = null;          switch (position) {             case 0:                 layout = layoutinflater.inflate(r.layout.lifestyle, container, false);                 text1 = (textview) layout.findviewbyid(r.id.text3);                 text2 = (textview) layout.findviewbyid(r.id.text4);                 text3 = (textview) layout.findviewbyid(r.id.text5);                 background = (imageview) layout.findviewbyid(r.id.background);                  background.setimageresource(r.drawable.tlifestyle);                 break;             case 1:                 layout = layoutinflater.inflate(r.layout.sports, container, false);                 text1 = (textview) layout.findviewbyid(r.id.text3);                 text2 = (textview) layout.findviewbyid(r.id.text4);                 text3 = (textview) layout.findviewbyid(r.id.text5);                 background = (imageview) layout.findviewbyid(r.id.background);                  background.setimageresource(r.drawable.tsports);                 break;             case 2:                 layout = layoutinflater.inflate(r.layout.events, container, false);                 text1 = (textview) layout.findviewbyid(r.id.text1);                 text2 = (textview) layout.findviewbyid(r.id.text2);                 text3 = (textview) layout.findviewbyid(r.id.text3);                 text4 = (textview) layout.findviewbyid(r.id.text4);                 background = (imageview) layout.findviewbyid(r.id.background);                  background.setimageresource(r.drawable.tevents);                 break;             case 3:                 layout = layoutinflater.inflate(r.layout.intro_to_categories, container, false);                 text1 = (textview) layout.findviewbyid(r.id.welcometext);                 text2 = (textview) layout.findviewbyid(r.id.findtext);                 text3 = (textview) layout.findviewbyid(r.id.dont_stress);                 text4 = (textview) layout.findviewbyid(r.id.dont_stress_2);                 begin = (button) layout.findviewbyid(r.id.begin);                  typeface typeface = typeface.createfromasset(getassets(), "mpashofont.otf");                 begin.settypeface(typeface);                  begin.setonclicklistener(new view.onclicklistener() {                     @override                     public void onclick(view view) {                         startactivity(new intent(apptutorial.this, appsetup.class));                     }                 });                 break;         }          typeface typeface = typeface.createfromasset(getassets(), "mpashofont.otf");         assert text1 != null && text2 != null && text3 != null;         text1.settypeface(typeface);         text2.settypeface(typeface);         text3.settypeface(typeface);         if (text4 != null) {             text4.settypeface(typeface);         }          container.addview(layout);          return layout;     }      @override     public void destroyitem(viewgroup container, int position, object object) {         container.removeview((framelayout) object);     } } 

i guess per code of adapter can see have 3 textview , 1 background image different inflated layouts.

and creating typeface on each swipe place typeface initialization code in constructor

and better change data per position.

like

    @override     public object instantiateitem(viewgroup container, int position) {     textview text1 = null, text2 = null, text3 = null, text4 = null;     imageview background;      view itemview = mlayoutinflater.inflate(r.layout.your_layout, container, false);     text1 = (textview) layout.findviewbyid(r.id.text3);     text2 = (textview) layout.findviewbyid(r.id.text4);     text3 = (textview) layout.findviewbyid(r.id.text5);     background = (imageview) layout.findviewbyid(r.id.background);     text1.settext(arr[position]);    ... } 

Comments