【问题标题】:Show more in Horizontal ScrollView in android在 android 的 Horizo​​ntal ScrollView 中显示更多
【发布时间】:2013-12-23 12:53:29
【问题描述】:

我不确定什么是最好的标题,但是有图片,我想要什么就很清楚了。

我已经实现了水平滚动视图,我已经定制了它,因为只有四个项目会显示,如果用户想看到第五个项目,那么他必须滚动它。 我已经成功地做到了。

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

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

【问题讨论】:

  • 查看这篇文章:stackoverflow.com/questions/8531006/… 将缓存提示颜色设置为透明。
  • 不@MarcelCăşvan 不是那样的,我想在最后显示白色视图,以便用户可以理解它,还有更多视图
  • 我明白了,当用户看到此活动时,您是否考虑过为滚动视图设置动画?就像动画滚动从右边的最后一个项目到第一个
  • 尝试为相同的 .在这里获取参考..stackoverflow.com/questions/18120510/…。否则尝试使用 Horizo​​ntalScrollView。
  • setOverScrollMode(View.OVER_SCROLL_ALWAYS);试试这个。

标签: android android-view android-scrollview


【解决方案1】:

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

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

}

【讨论】:

    猜你喜欢
    • 2015-06-13
    • 2021-10-22
    • 2021-03-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-22
    • 1970-01-01
    相关资源
    最近更新 更多