title: ViewPager image slider inside ScrollView
body: <p>I've got a problem with <code>ViewPager</code> inside <code>ScrollView</code>. I created adapter, that works properly when <code>LinearLayout</code> is a root layout. But when I switch to <code>ScrollView</code>, then it doesn't show any images. I need <code>ScrollView</code>, cause I have a few elements to display and it's have to be scrollable. My layout is in <code>activity_exercises_preview.xml</code> file.</p>
  
  <p>Layout, that doesn't work:</p>
  
  <pre><code>&lt;ScrollView
      xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:padding="5dp"
      android:background="@color/colorBackground"&gt;
  
      &lt;LinearLayout
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:orientation="vertical"&gt;
  
          &lt;android.support.v7.widget.CardView
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              app:cardCornerRadius="0dp"
              android:id="@+id/cv"
              &gt;
  
              &lt;LinearLayout
                  android:layout_width="match_parent"
                  android:layout_height="match_parent"
                  android:orientation="vertical"
                  android:minHeight="200dp"&gt;
  
                  &lt;android.support.v4.view.ViewPager
                      android:id="@+id/viewPager"
                      android:layout_width="fill_parent"
                      android:layout_height="fill_parent"&gt;
  
                  &lt;/android.support.v4.view.ViewPager&gt;
  
              &lt;/LinearLayout&gt;
  
          &lt;android.support.v7.widget.CardView...&gt;
  
          &lt;android.support.v7.widget.CardView...&gt;
  
          &lt;android.support.v7.widget.CardView...&gt;
  
      &lt;/LinearLayout&gt;
  
  &lt;/ScrollView&gt;
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/mJXNx.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mJXNx.jpg" alt="enter image description here"></a></p>
  
  <p>Layout, that works, but without ScrollView:</p>
  
  <pre><code>&lt;LinearLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:padding="5dp"
      android:background="@color/colorBackground"&gt;
  
      &lt;LinearLayout
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:orientation="vertical"&gt;
  
          &lt;android.support.v7.widget.CardView
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              app:cardCornerRadius="0dp"
              android:id="@+id/cv"
              &gt;
  
              &lt;LinearLayout
                  android:layout_width="match_parent"
                  android:layout_height="match_parent"
                  android:orientation="vertical"
                  android:minHeight="200dp"&gt;
  
                  &lt;android.support.v4.view.ViewPager
                      android:id="@+id/viewPager"
                      android:layout_width="fill_parent"
                      android:layout_height="fill_parent"&gt;
  
                  &lt;/android.support.v4.view.ViewPager&gt;
  
              &lt;/LinearLayout&gt;
  
          &lt;android.support.v7.widget.CardView...&gt;
  
          &lt;android.support.v7.widget.CardView...&gt;
  
          &lt;android.support.v7.widget.CardView...&gt;
  
      &lt;/LinearLayout&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/cMSSz.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/cMSSz.jpg" alt="enter image description here"></a></p>
  
  <p>My adapter:</p>
  
  <pre><code>public class CustomAdapter extends PagerAdapter{
  
      Context context;
      int[] imageId = {R.drawable.icon, R.drawable.gwiazdki, R.drawable.arnoldki_3};
  
      public CustomAdapter(Context context){
          this.context = context;
      }
  
      @Override
      public Object instantiateItem(ViewGroup container, int position) {
          // TODO Auto-generated method stub
  
          LayoutInflater inflater = ((Activity)context).getLayoutInflater();
  
          View viewItem = inflater.inflate(R.layout.image_item, container, false);
          ImageView imageView = (ImageView) viewItem.findViewById(R.id.imageView);
          imageView.setImageResource(imageId[position]);
          ((ViewPager)container).addView(viewItem);
  
          return viewItem;
      }
  
      @Override
      public int getCount() {
          // TODO Auto-generated method stub
          return imageId.length;
      }
  
      @Override
      public boolean isViewFromObject(View view, Object object) {
          // TODO Auto-generated method stub
  
          return view == ((View)object);
      }
  
  
      @Override
      public void destroyItem(ViewGroup container, int position, Object object) {
          // TODO Auto-generated method stub
          ((ViewPager) container).removeView((View) object);
      }
  }
  
      Activity:
  
  
  
  public class ExercisesPreview extends AppCompatActivity {
          List&lt;Exercise&gt; exercises;
          Exercise exercise;
          ViewPager viewPager;
  
          @Override
          protected void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              setContentView(R.layout.activity_exercises_preview);
  
              viewPager = (ViewPager) findViewById(R.id.viewPager);
              PagerAdapter adapter = new CustomAdapter(ExercisesPreview.this);
              viewPager.setAdapter(adapter);
              viewPager.setOnTouchListener(new View.OnTouchListener() {
                  @Override
                  public boolean onTouch(View v, MotionEvent event) {
                      viewPager.getParent().requestDisallowInterceptTouchEvent(true);
                      return false;
                  }
              });
  
          }
      (...)
      }
  </code></pre>
  
  <p>image_item.xml:</p>
  
  <pre><code>&lt;LinearLayout 
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="vertical" &gt;
  
      &lt;ImageView
          android:id="@+id/imageView"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          /&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>Any ideas?</p>