문제

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.

도움이 되었습니까?

해결책

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top