This article from: http://stackoverflow.com/questions/6778883/surfaceview-horizontal-scrolling
Q:
|
I'm writing an application which will create a graph and draw it on a surfaceview. Eventually the graph needs to be able to update live But for now I want the surfaceview TO BE scrollable horizontally So that the user can see all the data. Is this possible? |
A:
You need to place your custom view inside a horizontal scroll view as a separeate class.
When you create an instace of your custom Graph view you tell it to size itself
According to the width of the graph by overriding the onmeasure method:
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
this.setMeasuredDimension(graphWidth, graphHeight);
}
Graphwidth = barlenghtinpixels * barcount + extraspaceinpixels;
You can place your customview in an XML layout using a custom tag like<com.myApplication.GraphView...>
Or useMyscrollview. addview (mycustomview)And add it into the horizontalscrollview,
Before you call setcontentview (mylayout ).
"Horizontalscrollview myscrollview = new horizontalscrollview (this)" shocould be within oncreate