2013-12-23 57 views
6

我不確定什麼是最好的標題,但是用圖片,它會清楚我想要什麼。在android的水平滾動視圖中顯示更多內容

我已經實現了水平滾動視圖,我已經定製,只有四個項目將被顯示,如果用戶想看第五個項目,那麼他必須滾動它。 我已經成功地做到了。

但是在android 2.3.3中它顯示白色視圖在末尾當有更多的項目,而在android 4.0它不顯示。見下圖:這裏的Android 2.3

enter image description here

看,我露出雪白的觀點這清楚地告訴我說,有更多的按鈕,但同樣的結果,我不是在Android 4.0以上獲得以上。
任何人都可以幫助我如何顯示它。

+0

看到這個職位:http://stackoverflow.com/questions/8531006/list-color-在滾動時變成黑色 將緩存提示顏色設置爲透明。 – androidu

+0

不是@MarcelCăşvan它不是這樣,我想在最後顯示白色視圖,以便用戶可以理解它,有更多的視圖 –

+0

我看到,你有沒有考慮給用戶提供這個活動的動畫scrollview?就像從右側最後一項到第一個 – androidu

回答

3

您可以輕鬆地通過擴展HorizontalScrollView部件和圖紙2妥善放置圖像/繪項目複製這種行爲:

public class CustomHorizontalScrollView extends HorizontalScrollView { 

    private static final int SHADOW_WIDTH = 35; 
    private GradientDrawable mDrawableLeft; 
    private GradientDrawable mDrawableRight; 
    private Rect mBounds = new Rect(); 

    public CustomHorizontalScrollView(Context context, AttributeSet attrs) { 
     super(context, attrs); 
     mDrawableLeft = new GradientDrawable(Orientation.LEFT_RIGHT, 
       new int[] { Color.GRAY, Color.TRANSPARENT }); 
     mDrawableRight = new GradientDrawable(Orientation.RIGHT_LEFT, 
       new int[] { Color.GRAY, Color.TRANSPARENT }); 
    } 

    @Override 
    protected void dispatchDraw(Canvas canvas) { 
     super.dispatchDraw(canvas); 
     // the scroll value 
     final int offset = this.getScrollX(); 
     mBounds.setEmpty(); 
     mBounds.bottom = getMeasuredHeight(); 
     // check made to remove the shadow if we are at the left edge of the 
     // screen so we don't interfere with the edge effect 
     if (offset != 0) { 
      // left drawable 
      mBounds.left = offset; 
      mBounds.right = offset + SHADOW_WIDTH; 
      mDrawableLeft.setBounds(mBounds); 
      mDrawableLeft.draw(canvas); 
     } 
     // check made to remove the shadow if we are at the right edge of the 
     // screen so we don't interfere with the edge effect 
     if ((offset + getMeasuredWidth()) < computeHorizontalScrollRange()) { 
      // right drawable 
      mBounds.left = offset + getMeasuredWidth() - SHADOW_WIDTH; 
      mBounds.right = offset + getMeasuredWidth(); 
      mDrawableRight.setBounds(mBounds); 
      mDrawableRight.draw(canvas); 
     } 
    } 

} 
+0

非常感謝你@Luksprog工作正常 –