Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Mark Murphy has <a href="http://commonsware.com/blog/2012/08/20/multiple-view-viewpager-options.html" rel="nofollow noreferrer">an interesting blog post addressing precisely this problem</a>. Although I ended up using <a href="https://stackoverflow.com/a/15006910/154306">my own solution in this thread</a>, it's worthwhile looking at Dave Smith's code, which Mark references in the blog post:</p> <blockquote> <p><a href="https://gist.github.com/8cbe094bb7a783e37ad1" rel="nofollow noreferrer">https://gist.github.com/8cbe094bb7a783e37ad1/</a></p> </blockquote> <p><strong>Warning!</strong> <em>Before you take this approach, beware of some very serious issues with this approach, mentioned both at the end of this post and in the comments below.</em></p> <p>You'll end up with this:</p> <p><img src="https://i.stack.imgur.com/VOxxv.png" alt="Screenshot of Dave Smith&#39;s PagerContainer"></p> <p>It effectively works by wrapping a <code>ViewPager</code> into a subclass of <code>FrameLayout</code>, setting it to a specific size, and calling <code>setClipChildren(false)</code>. This inhibits Android from clipping the views that exceed beyond the boundaries of the <code>ViewPager</code>, and visually accomplishes what you want.</p> <p>In XML, it's very simple:</p> <pre><code>&lt;com.example.pagercontainer.PagerContainer android:id="@+id/pager_container" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#CCC"&gt; &lt;android.support.v4.view.ViewPager android:layout_width="150dp" android:layout_height="100dp" android:layout_gravity="center_horizontal" /&gt; &lt;/com.example.pagercontainer.PagerContainer&gt; </code></pre> <p>Add in a little code for handling touch events from outside of the <code>ViewPager</code> and invalidating the display when scrolling, and you're done.</p> <p>That being said, and while this works great in general, I did notice that there is an edge-case that isn't solved with this fairly simple construction: when calling <code>setCurrentPage()</code> on the <code>ViewPager</code>. The only way I could find to resolve this was by subclassing <code>ViewPager</code> itself and having its <code>invalidate()</code> function also invalidate the <code>PagerContainer</code>.</p>
    singulars
    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.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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