Note that there are some explanatory texts on larger screens.

plurals
  1. POSimple ViewPager - Single Layout
    text
    copied!<p>I'm trying to do a simple ViewPager from an array of images.</p> <p>My array is:</p> <pre><code>&lt;string-array name="ot_images"&gt; &lt;item&gt;"file:///android_res/drawable/ot_100.jpg"&lt;/item&gt; &lt;item&gt;"file:///android_res/drawable/ot_101.jpg"&lt;/item&gt; &lt;item&gt;"file:///android_res/drawable/ot_102.jpg"&lt;/item&gt; &lt;item&gt;"file:///android_res/drawable/ot_103.jpg"&lt;/item&gt; </code></pre> <p>My Layout is:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" &gt; &lt;ImageView android:id="@+id/iView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" /&gt; &lt;/RelativeLayout&gt; </code></pre> <p>And so far MyPagerAdapter.java</p> <pre><code>public class MyPagerAdapter extends PagerAdapter{ public int getCount() { return 5; } public Object instantiateItem(View collection, int position) { LayoutInflater inflater = (LayoutInflater) collection.getContext() .getSystemService(Context.LAYOUT_INFLATER_SERVICE); int resId = 0; switch (position) { case 0: resId = R.layout.farleft; break; case 1: resId = R.layout.left; break; case 2: resId = R.layout.middle; break; case 3: resId = R.layout.right; break; case 4: resId = R.layout.farright; break; } View view = inflater.inflate(resId, null); ((ViewPager) collection).addView(view, 0); return view; } @Override public void destroyItem(View arg0, int arg1, Object arg2) { ((ViewPager) arg0).removeView((View) arg2); } @Override public boolean isViewFromObject(View arg0, Object arg1) { return arg0 == ((View) arg1); } @Override public Parcelable saveState() { return null; } } </code></pre> <p>I've followed this tutorial: <a href="http://mobile.tutsplus.com/tutorials/android/android-user-interface-design-horizontal-view-paging/" rel="nofollow">Android User Interface Design: Horizontal View Paging</a></p> <p>Everything is working fine, but my question is:</p> <p>How do you use this tutorial with 1 layout instead of 5? Thank you!</p>
 

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