Reputation: 2899
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?
Upvotes: 1
Views: 3047
Reputation: 21629
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 use myScrollView.addView(myCustomView)
and add it into the HorizontalScrollView
, before you call setContentView(myLayout)
.
Upvotes: 2
Reputation: 5759
Place a HorizontalScrollView element inside surface view. Look at gatherTransparentRegion(Region region) in the HorizontalScrollView documentation
Upvotes: 1