【问题标题】:Custom view scrollbars自定义视图滚动条
【发布时间】:2012-06-01 08:12:04
【问题描述】:

我有一个自定义视图,我设法使用这篇文章在其上启用滚动条:Android: Enable Scrollbars on Canvas-Based View。 问题是我无法滚动它们,即使我覆盖了计算函数。 下面是创建视图的代码:

final PaintBoardView paintBoardView=new PaintBoardView(this);
LinearLayout.LayoutParams layoutParams=new LinearLayout.LayoutParams(
        0,ViewGroup.LayoutParams.FILL_PARENT,(float)0.8);
paintBoardView.setLayoutParams(layoutParams);
ViewGroup boardToolsContainer=(ViewGroup)findViewById(R.id.board_tools_container);
boardToolsContainer.addView(paintBoardView);

这是视图的构造函数:

super(context);
setBackgroundResource(android.R.color.white);
setHorizontalScrollBarEnabled(true);
setVerticalScrollBarEnabled(true);
TypedArray styledAttributes=context.obtainStyledAttributes(
    R.styleable.View);
initializeScrollbars(styledAttributes);
styledAttributes.recycle();

还有:

@Override public int computeHorizontalScrollRange() { return 2000; }
@Override public int computeVerticalScrollRange() { return 2000; }

正如我所说,我看到滚动条,但滚动不起作用。 感谢您的帮助。

【问题讨论】:

    标签: android android-view android-scrollbar


    【解决方案1】:

    最后我只是使用视图的 scrollBy 和 scrollTo 方法在 onTouchEvent 函数中自己进行滚动。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-08
      • 2011-11-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-13
      相关资源
      最近更新 更多