2012-08-09 23 views
1
兩側模糊效果

我意識到,對於谷歌播放市場,他們已經在左右「模糊」效果(參見「付費」上左,上右「趨勢」,作爲附件)創建於ViewPagerIndicator

我在想,是否可以使用ViewPagerIndicator來實現這樣的效果?從我看到的演示中,我們可以自定義各種指標(從一行到三個)。但我還沒有看到一個例子,它會在左側產生「模糊」效應。

enter image description here

回答

4

我想知道,是有可能實現使用 ViewPagerIndicator這樣的效果呢?

你可以擴展TitlePagerIndicator,並簡單的畫出衰落邊緣自己:

public class TitlePageIndicatorFade extends TitlePageIndicator { 

    private GradientDrawable mDrawableLeft, mDrawableRight; 
    private static final int FADE_SIZE = 30; 

    public TitlePageIndicatorFade(Context context, AttributeSet attrs, 
      int defStyle) { 
     super(context, attrs, defStyle); 
     init(); 
    } 

    public TitlePageIndicatorFade(Context context, AttributeSet attrs) { 
     super(context, attrs); 
     init(); 
    } 

    public TitlePageIndicatorFade(Context context) { 
     super(context); 
     init(); 
    } 

    private void init() { 
     mDrawableLeft = new GradientDrawable(
       GradientDrawable.Orientation.LEFT_RIGHT, new int[] { 
         Color.parseColor("#F9F9F9"), 
         Color.parseColor("#00000000") }); 
     mDrawableRight = new GradientDrawable(
       GradientDrawable.Orientation.RIGHT_LEFT, new int[] { 
         Color.parseColor("#F9F9F9"), 
         Color.parseColor("#00000000") }); 
    } 

    @Override 
    protected void onDraw(Canvas canvas) { 
     super.onDraw(canvas); 
     mDrawableLeft.setBounds(0, 0, FADE_SIZE, getHeight()); 
     mDrawableRight.setBounds(getWidth()- FADE_SIZE, 0, getWidth(), 
       getHeight()); 
     mDrawableLeft.draw(canvas); 
     mDrawableRight.draw(canvas); 
    } 

}