title: Android: Drawing on Canvas in Scrollview
body: <p>I'm pretty much new in programing for Android. My app is sample app from api demos on developer android website. When I change parameters in that sample drawing it gets larger . That drawing needs to be displayed in scroll view (it doesn't need to be shrinked to fit the screen). This is the code I used:</p>
  
  <p><strong>DrawPoints.java</strong></p>
  
  <pre><code>    public class DrawPoints extends myActivity {
  
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.routes); 
  
      }
  
      public static class SampleView extends View {
          private Paint   mPaint = new Paint();
          private float[] mPts;
  
         /*here comes declaration of parametars
  
  
  
          private void buildPoints() {
  
          /*here comes some coding*/
  
              }
          }
  
          public SampleView(Context context, AttributeSet attributeset) {
              super(context, attributeSet);
  
              buildPoints();
          }
  
          @Override 
          protected void onDraw(Canvas canvas) {
              Paint paint = mPaint;
  
              //here also comes code
          }
      }
  }
  </code></pre>
  
  <p>here is xml Code:</p>
  
  <p><strong>routes.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
      &lt;ScrollView 
              xmlns:android="http://schemas.android.com/apk/res/android"
              android:id="@+id/scrollView1"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent" &gt;
          &lt;HorizontalScrollView 
                  android:id="@+id/scrollView2"
                  android:layout_width="fill_parent"
                  android:layout_height="fill_parent"&gt;
  
                      &lt;!-- This code is just to make sure that scroll views work how 
                          I want them to work, image size is 625*351 px
                       &lt;ImageView
                          android:id="@+id/image_View1"
                          android:layout_width="fill_parent"
                          android:layout_height="fill_parent"
                          android:src="@drawable/bus_design"
                              /&gt; --&gt;
                       &lt;my.package.DrawPoints.SampleView
                          android:layout_width="fill_parent" 
                          android:layout_height="fill_parent" /&gt; 
  
  
          &lt;/HorizontalScrollView&gt;
      &lt;/ScrollView&gt;
  </code></pre>
  
  <p>When I run that application and push the button in main activity application crashes. 
  Drawing looks like Figure1 when I'm not using xml layout or scrollviews:</p>
  
  <p><a href="http://i.stack.imgur.com/za5MP.png" rel="noreferrer">http://i.stack.imgur.com/za5MP.png</a>
           <strong>Figure1</strong></p>
  
  <p>I also tried to use this code after method setContentView:</p>
  
  <pre><code>View v = new SampleView(this);
  addContentView(v, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
              ViewGroup.LayoutParams.FILL_PARENT));
  </code></pre>
  
  <p>and also this one:</p>
  
  <pre><code>View v = new SampleView(this);
      ScrollView.LayoutParams lp = new ScrollView.LayoutParams(1000, 1000);
  
      addContentView(v, lp);
  </code></pre>
  
  <p>when I use codes, shown above, app displays Figure1 without scrollview, it seems like second content view overwrites that xml but it doesn't show correctly. 
  After that I tried to use this code after setContentView:</p>
  
  <pre><code>View v = new SampleView(this);
      FrameLayout fl = new FrameLayout(this);
      fl.findViewById(R.id.FrameLayout1);
      fl.addView(v);
  </code></pre>
  
  <p>Frame layout (FrameLayout1) is added in routes.xml file after horizontal scroll view. When application runs I get blank screen without Figure1.
  Does Anyone have an idea how to upgrade my code that would display Figure1 in ScrollView?</p>
  
  <p>Thanks in advance!</p>