Domanda

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.

È stato utile?

Soluzione

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

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top