【发布时间】: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