zoukankan      html  css  js  c++  java
  • [转]SurfaceView horizontal scrolling

    本文转自:http://stackoverflow.com/questions/6778883/surfaceview-horizontal-scrolling

    问:

     

    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:

    @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).

    "HorizontalScrollView myScrollView = new HorizontalScrollView(this)" should be within onCreate

  • 相关阅读:
    2-1(续)
    2-1
    28-69. Sqrt(x)
    27-75. Sort Colors
    26-78. Subsets
    MySQL--->存储引擎及图形化工具
    MySQL--->高级对象
    MySQL--->常用函数
    MySQL--->多表查询
    MySQL--->高级查询
  • 原文地址:https://www.cnblogs.com/freeliver54/p/2534557.html
Copyright © 2011-2022 走看看