Surfaceview horizontal scrolling

Source: Internet
Author: User

This article from:



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?




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:

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




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.