2015-12-15 51 views
2

如何在Android中創建垂直視圖尋呼機,就像在NewsInShort應用程序中。 https://play.google.com/store/apps/details?id=com.nis.appAndroid垂直視圖尋呼機像NewsInShort應用程序

這個程序包含新聞提要,當我們向上滑動下一個新聞出現與動畫當前的新聞一樣,如果我向上輕掃當前的新聞一點點那麼接下來的消息顯示,這樣的方式。 一樣的向下滑動。

我在Github上找到了一個庫。
https://github.com/rharter/ViewPager-Android

但是這個庫沒有提供像NewsInShort App這樣的東西。

如果有人曾經創建過這樣的視圖或庫,請告訴我。

謝謝。

回答

1

經過長期研究,我找到了解決方案。
對於ViewPager,我們可以設置pageTransformer屬性並分配自定義轉換。
我想要的轉換是DepthPageTransformer。以下是轉化記錄的鏈接。
https://stuff.mit.edu/afs/sipb/project/android/docs/training/animation/screen-slide.html#depth-page

public class DepthPageTransformer implements ViewPager.PageTransformer { 
    private static float MIN_SCALE = 0.75f; 

    public void transformPage(View view, float position) { 
     int pageWidth = view.getWidth(); 

     if (position < -1) { // [-Infinity,-1) 
      // This page is way off-screen to the left. 
      view.setAlpha(0); 

     } else if (position <= 0) { // [-1,0] 
      // Use the default slide transition when moving to the left page 
      view.setAlpha(1); 
      view.setTranslationX(0); 
      view.setScaleX(1); 
      view.setScaleY(1); 

     } else if (position <= 1) { // (0,1] 
      // Fade the page out. 
      view.setAlpha(1 - position); 

      // Counteract the default slide transition 
      view.setTranslationX(pageWidth * -position); 

      // Scale the page down (between MIN_SCALE and 1) 
      float scaleFactor = MIN_SCALE 
        + (1 - MIN_SCALE) * (1 - Math.abs(position)); 
      view.setScaleX(scaleFactor); 
      view.setScaleY(scaleFactor); 

     } else { // (1,+Infinity] 
      // This page is way off-screen to the right. 
      view.setAlpha(0); 
     } 
    } 
}