Question

I have a custom view and I managed to enable scrollbars on it using this post: Android: Enable Scrollbars on Canvas-Based View. The problem is that I can't scroll them, even though I overrode the compute functions. Here is the code that creates the 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);

And here's the view's constructor:

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

And:

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

As I said, I see the scroll bars, but the scrolling is not working. Thanks for any help.

Was it helpful?

Solution

In the end I'm just using the view's scrollBy and scrollTo methods to do the scrolling myself in the onTouchEvent function.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top