2015-05-25 347 views

回答

2

在你的materialViewView中,你應該實現這個功能! 這部分做魔術!

@Override 
     public void setPrimaryItem(ViewGroup container, int position, Object object) { 
      super.setPrimaryItem(container, position, object); 

      //only if position changed 
      if (position == oldPosition) 
       return; 
      oldPosition = position; 

      int color = 0; 
      String imageUrl = ""; 
      switch (position) { 
       case 0: 
        imageUrl = "http://cdn1.tnwcdn.com/wp-content/blogs.dir/1/files/2014/06/wallpaper_51.jpg"; 
        color = getResources().getColor(R.color.blue); 
        break; 
       case 1: 
        imageUrl = "https://fs01.androidpit.info/a/63/0e/android-l-wallpapers-630ea6-h900.jpg"; 
        color = getResources().getColor(R.color.green); 
        break; 
       case 2: 
        imageUrl = "http://www.droid-life.com/wp-content/uploads/2014/10/lollipop-wallpapers10.jpg"; 
        color = getResources().getColor(R.color.cyan); 
        break; 
       case 3: 
        imageUrl = "http://www.tothemobile.com/wp-content/uploads/2014/07/original.jpg"; 
        color = getResources().getColor(R.color.red); 
        break; 
      } 

      final int fadeDuration = 400; 
      mViewPager.setImageUrl(imageUrl, fadeDuration); 
      mViewPager.setColor(color, fadeDuration); 
      mViewPager.resetOffset(position); 
     } 
0

是,在新版本中,你應該使用

mViewPager.setMaterialViewPagerListener(new MaterialViewPager.MaterialViewPagerListener() { 
      @Override 
      public HeaderDesign getHeaderDesign(int page) { 
       switch (page) { 
        case 0: 
         return HeaderDesign.fromColorResAndUrl(
           R.color.blue, 
           "http://cdn1.tnwcdn.com/wp-content/blogs.dir/1/files/2014/06/wallpaper_51.jpg"); 
        case 1: 
         return HeaderDesign.fromColorResAndUrl(
           R.color.green, 
           "https://fs01.androidpit.info/a/63/0e/android-l-wallpapers-630ea6-h900.jpg"); 
        case 2: 
         return HeaderDesign.fromColorResAndUrl(
           R.color.cyan, 
           "http://www.droid-life.com/wp-content/uploads/2014/10/lollipop-wallpapers10.jpg"); 
        case 3: 
         return HeaderDesign.fromColorResAndUrl(
           R.color.red, 
           "http://www.tothemobile.com/wp-content/uploads/2014/07/original.jpg"); 
       } 

       //execute others actions if needed (ex : modify your header logo) 

       return null; 
      } 
     }); 
+0

如何設置衰落期在新的實現??? – Kay