Note that there are some explanatory texts on larger screens.

plurals
  1. POViewPager inside ScrollView - vertical scroll doesn't work
    primarykey
    data
    text
    <p>So, I have this <code>ScrollView</code> with one child - a <code>LinearLayout</code> that has two children: a <code>TextView</code> and a <code>ViewPager</code>. <code>ViewPager</code> contains layout with many elements, that's why i need the ability to scroll vertically. Only pages in <code>ViewPager</code> may be scrolled horizontally (that is: I'd like to swipe horizontally only within the <code>ViewPager</code>). That one <code>TextView</code> must not scroll horizontally but should scroll together with my <code>ViewPager</code>.</p> <p>Simple? No.</p> <p>I've seen extremely similar issues at StackOverflow popping up (<a href="https://stackoverflow.com/questions/8381697/viewpager-inside-a-scrollview-does-not-scroll-correclty">here</a>, <a href="https://stackoverflow.com/questions/2646028/android-horizontalscrollview-within-scrollview-touch-handling">here</a> and <a href="https://stackoverflow.com/questions/10865508/viewpager-in-scrollview-wont-scroll-vertically">here</a> and <a href="https://stackoverflow.com/questions/7381360/is-it-possible-to-have-a-viewpager-inside-of-a-scrollview">here</a>). None of the suggested solutions work for me :(</p> <p>What I see is <a href="http://postimage.org/image/uy98ro5nl/" rel="nofollow noreferrer">this</a> &lt;- my sweet UI :), However I cannot scroll vertically :(</p> <p>Embedding ScrollViews inside ViewPager is not an option - desing of the UI forbids this.</p> <p>Maybe it's something with my programmatically filling each page in view pager? Hmmm...</p> <p>Any suggestions would be appreciated.</p> <p>My code:</p> <p>activity_main.xml:</p> <pre><code>&lt;ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/scrollView" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@android:color/white" android:fillViewport="true" &gt; &lt;LinearLayout android:id="@+id/linearLayoutGeneral" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical"&gt; &lt;TextView android:id="@+id/tvText" android:layout_width="fill_parent" android:layout_height="200dp" android:text="Test text" /&gt; &lt;android.support.v4.view.ViewPager android:id="@+android:id/viewpager" android:layout_width="fill_parent" android:layout_height="fill_parent" &gt; &lt;/android.support.v4.view.ViewPager&gt; &lt;/LinearLayout&gt; &lt;/ScrollView&gt; </code></pre> <p>each page in ViewPager has this layout:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" &gt; &lt;LinearLayout android:id="@+id/layoutData" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" &gt; &lt;/LinearLayout&gt; &lt;/LinearLayout&gt; </code></pre> <p>single element's layout in such a page:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="40dp" android:gravity="center" android:orientation="vertical" android:background="@android:color/white" &gt; &lt;TextView android:id="@+id/textView" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Large Text" android:background="@android:color/black" android:textColor="@android:color/white" android:textAppearance="?android:attr/textAppearanceLarge" /&gt; &lt;/LinearLayout&gt; </code></pre> <p>A single page Fragment is also very simple:</p> <pre><code>public class DayFragment extends Fragment { private static final String TAG = DayFragment.class.getSimpleName(); public String tag; LinearLayout data; View mView; final int ROWS_NUM = 60; public DayFragment() { } /** * (non-Javadoc) * * @see android.support.v4.app.Fragment#onCreateView(android.view.LayoutInflater, * android.view.ViewGroup, android.os.Bundle) */ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { if (container == null) { // We have different layouts, and in one of them this // fragment's containing frame doesn't exist. The fragment // may still be created from its saved state, but there is // no reason to try to create its view hierarchy because it // won't be displayed. Note this is not needed -- we could // just run the code below, where we would create and return // the view hierarchy; it would just never be used. return null; } mView = (LinearLayout) inflater.inflate(R.layout.day, container, false); setUpControls(); generateData(); String text = getArguments().getString("text"); Log.d(TAG, "creating view with text: " + text); return mView; } private void setUpControls() { data = (LinearLayout) mView.findViewById(R.id.layoutData); } private void generateData() { for (int i = 0; i &lt; ROWS_NUM; i++) { View v = createRow(i); data.addView(v); } } private View createRow(int num) { LayoutInflater inflater = (LayoutInflater) getActivity() .getSystemService(Context.LAYOUT_INFLATER_SERVICE); View v = inflater.inflate(R.layout.row, null); TextView tv = (TextView) v.findViewById(R.id.textView); tv.setText("Data nr: " + num); return v; } public static DayFragment newInstance(String text) { Log.d(TAG, "newInstance with text: " + text); DayFragment f = new DayFragment(); f.tag = text; // Supply text input as an argument. Bundle args = new Bundle(); args.putString("text", text); f.setArguments(args); return f; } } </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.
    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