title: Changing ScrollView (Horizontal/Vertical) in layout and layout-land
body: <p>I have created a layout-land folder and copied my activity_main.xml file so that I can re-position some views to make it more optimised for landscape viewing. Everything is fine until I change my <code>ScrollView</code>; portrait uses vertical and landscape uses horizontal. My app will then crash as it cannot cast ScrollView into HorizontalScrollView and vice versa.</p>
  
  <pre><code>android.widget.ScrollView cannot be cast to android.widget.HorizontalScrollView
  </code></pre>
  
  <p>Unfortunately both of the orientations cannot use the same <code>HorizontalScrollView</code> or <code>VerticalScrollView</code> as it will become messed up and not possible to use the scrolling feature as intended.</p>
  
  <p>I have looked on stackoverflow and google but could not find anything relevant probably due to the wording of the problem. What would be the best solution? Would I have to create the <code>ScrollView</code> within Java code and not via xml?</p>
  
  <p>EDIT - requested code:
  Okay so my MainActivity onCreate() has</p>
  
  <pre><code>ScrollView scrollView = (ScrollView) findViewById(R.id.scrollView);
  </code></pre>
  
  <p>In my layout\activity_main.xml I am using </p>
  
  <pre><code>&lt;ScrollView
          android:layout_width="wrap_content"
          android:layout_height="match_parent"
          android:id="@+id/scrollView"
          android:visibility="visible"&gt;
  ....
  &lt;/ScrollView&gt;
  </code></pre>
  
  <p>In land\activity_main.xml</p>
  
  <pre><code>&lt;HorizontalScrollView
          android:layout_width="wrap_content"
          android:layout_height="match_parent"
          android:id="@+id/scrollView"
          android:visibility="visible"&gt;
  ....
  &lt;/HorizontalScrollView&gt;
  </code></pre>