2017-03-05 73 views
0

我設置了一組圖像查看尋呼機我希望圖像自動滾動,但在慢動作。我的問題是圖像移動速度非常快怎麼解決怎麼做,在我的代碼 尋呼機adapter`減慢viewpager

public class CustomerAdapter extends PagerAdapter { 
//private int[] images = {R.mipmap.img1,R.mipmap.img2,R.mipmap.img3,R.mipmap.img4}; 
private Context ctx; 
private String[] urls; 
private LayoutInflater inflater; 
final Handler handler = new Handler(); 
public Timer swipeTimer ; 

public CustomerAdapter(Context ctx,String []urls){ 
    this.ctx = ctx; 
    this.urls=urls; 
} 
@Override 
public int getCount() { 
    return urls.length; 
} 

@Override 
public boolean isViewFromObject(View view, Object object) { 
    return (view ==(LinearLayout)object); 
} 

@Override 
public Object instantiateItem(ViewGroup container, int position) { 
    inflater = (LayoutInflater)ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    View v = inflater.inflate(R.layout.swip,container,false); 
    ImageView img =(ImageView)v.findViewById(R.id.itemview); 

    Picasso.with(ctx).load(urls[position]).into(img); 


    container.addView(v); 
    return v; 
} 

@Override 
public void destroyItem(View container, int position, Object object) { 
    container.refreshDrawableState(); 
} 
public void setTimer(final ViewPager myPager, int time, final int numPages, final int curPage){ 

    final Runnable Update = new Runnable() { 
     int NUM_PAGES =numPages; 
     int currentPage = curPage ; 
     public void run() { 
      if (currentPage == NUM_PAGES) { 
       currentPage = 0; 
      } 
      myPager.setCurrentItem(currentPage++, true); 
     } 
    }; 

    swipeTimer = new Timer(); 
    swipeTimer.schedule(new TimerTask() { 

     @Override 
     public void run() { 
      handler.post(Update); 
     } 
    }, 1000, time*1000); 

} 
public void stopTimer(){ 
    //handler.removeCallbacks(null); 
    swipeTimer.cancel(); 
} 
} 

在我的炫魅

ViewPager viewPager = (ViewPager)convertView.findViewById(R.id.view_pager); 
    adapter = new CustomerAdapter(getContext(),imagesfortest); 
    viewPager.setAdapter(adapter); 
    viewPager.setCurrentItem(0); 
    adapter.setTimer(viewPager,5000,4,imagesfortest.length); 

回答

0

組變換。 Reference

mPager.setPageTransformer(true, new ZoomOutPageTransformer()); 

然後自定義變換動畫。

+0

它幫助我淡入淡出當圖像移動但仍然移動得非常快 –

+0

是的,這就是動畫。所以你可以控制它做任何你想要的。淡入淡出或縮放只是示例。 –

+0

好的,我明白了非常感謝。 –