Note that there are some explanatory texts on larger screens.

plurals
  1. POViewPager inside a ScrollView does not scroll correclty
    primarykey
    data
    text
    <p>I have a 'page' that has a number of components on it, and who's content is longer than the height of the device. Fine, just put all of the layout (the entire page) inside a <code>ScrollView</code>, no problem.</p> <p>One of the components is a <code>ViewPager</code>. This renders correctly, but the response to a swipe/fling is not performing correctly, it is jittery and doesn't always work. It seems to be getting 'confused' with the <code>ScrollView</code>, so only works 100% when you fling in an exact horizontal line.</p> <p>If I remove the <code>ScrollView</code>, the ViewPager responds perfectly.</p> <p>I've had a search around and have not found this as a known defect. Has anyone else experienced this?</p> <ul> <li>Platform Version: 1.6</li> <li>Compatibility Library v4. </li> <li>Device: HTC Incredible S</li> </ul> <p>Below is some example code for you to test with, comment out <code>ScrollView</code> to see it working correctly.</p> <p>Activity:</p> <pre><code>package com.ss.activities; import com.ss.R; import android.app.Activity; import android.content.Context; import android.graphics.Color; import android.os.Bundle; import android.os.Parcelable; import android.support.v4.view.PagerAdapter; import android.support.v4.view.ViewPager; import android.view.View; import android.widget.TextView; public class PagerInsideScollViewActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); ViewPager vp = (ViewPager) findViewById(R.id.viewpager); vp.setAdapter(new MyPagerAdapter(this)); } } class MyPagerAdapter extends PagerAdapter { private Context ctx; public MyPagerAdapter(Context context) { ctx = context; } @Override public int getCount() { return 2; } @Override public Object instantiateItem(View collection, int position) { TextView tv = new TextView(ctx); tv.setTextSize(50); tv.setTextColor(Color.WHITE); tv.setText("SMILE DUDE, SMILE DUDE, SMILE DUDE, SMILE DUDE, SMILE DUDE, " + "SMILE DUDE, SMILE DUDE, SMILE DUDE, SMILE DUDE, SMILE DUDE, " + "SMILE DUDE, SMILE DUDE, SMILE DUDE, SMILE DUDE, SMILE DUDE, " + "SMILE DUDE, SMILE DUDE, SMILE DUDE"); ((ViewPager) collection).addView(tv); return tv; } @Override public void destroyItem(View collection, int position, Object view) { ((ViewPager) collection).removeView((View) view); } @Override public boolean isViewFromObject(View view, Object object) { return view == object; } @Override public Parcelable saveState() { return null; } @Override public void restoreState(Parcelable arg0, ClassLoader arg1) { } @Override public void startUpdate(View arg0) { } @Override public void finishUpdate(View arg0) { } } </code></pre> <p>Layout:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" &gt; &lt;LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" &gt; &lt;android.support.v4.view.ViewPager android:id="@+id/viewpager" android:layout_width="fill_parent" android:layout_height="300dp" /&gt; &lt;/LinearLayout&gt; &lt;/ScrollView&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload