gpt4 book ai didi

android - 在 android 的 Horizo​​ntal ScrollView 中显示更多

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:11:22 25 4
gpt4 key购买 nike

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

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

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

enter image description here

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

最佳答案

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

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

}

关于android - 在 android 的 Horizo​​ntal ScrollView 中显示更多,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20744037/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com