在Android中的Horizo​​ntal ScrollView中显示更多内容

Sid*_*mit 6 android android-scrollview android-view

我不确定什么是最好的头衔,但有了图片,我很清楚我想要什么.

我已经实现了Horizo​​ntal Scrollview,我已经定制了它,因为只显示了四个项目,如果用户想看第五个项目,那么他必须滚动它.我成功地完成了它.

但是在android 2.3.3中,当有更多项目时它会在最后显示白色视图,而在android 4.0中它没有显示.见下图:

在此输入图像描述

在android 2.3中看这里,我正在显示白色视图,它清楚地告诉我,有更多按钮,但同样的结果我没有进入android 4.0或更高版本.
任何人都可以帮我如何显示它.

Luk*_*rog 4

HorizontalScrollView您可以通过扩展小部件并绘制两个正确放置的图像/绘图来轻松复制该行为:

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);
        }
    }

}
Run Code Online (Sandbox Code Playgroud)