1

Does anyone know how you can use ScrollView in a fragment using the Tabbed Activity Template when creating a new activity. It uses a viewPager by default, and I've made 3 tabs with 3 different layouts which I can slide through. But every time i try to use the ScrollView in any one of these tabs the program gets buggy and nothing happens, sometimes i can't even swipe. So, in different words:

My Question: What is the proper way to use scrollview in a tab(fragment) when using the default tabbed activity template with ViewPager?

UPDATE 1

The thing with NestedScrollView worked, but now this is the new problem that came along with the solution. The AppBar scrolls along with the other stuff. How can i fix this?

CLICK HERE TO SEE IMAGE

UPDATE 2

It looks like the scrollView has an effect on this type of AppBar (Toolbar to be more specific), and i just fixed the problem by adding app:layout_scrollFlags="enterAlwaysCollapsed" to <android.support.v7.widget.Toolbar/>, and it's now stationary.

Additional link:

https://developer.android.com/reference/android/support/design/widget/AppBarLayout.LayoutParams.html#SCROLL_FLAG_ENTER_ALWAYS_COLLAPSED

  • Try the answer below - I believe I had an issue like this before! – Eenvincible Oct 06 '16 at 15:43
  • This use case is widely covered in tutorials and you can find answers to the issues presented while implementing it here on SO. The advice from @Eenvincible sounds right to me. Good luck – Chisko Oct 06 '16 at 16:14

2 Answers2

2

For reasons that might seem unclear to most of us, it is hard for touch events to be differentiated when you want to scroll vs swipe.

To solve this, I used a NestedScrollView instead of the regular ScrollView.

The other option would be to catch the events and override them - obviously more complicated to do but possible.

You can take a look at my recent code on github for an example.

Good luck and please let me know if it works for you!

Eenvincible
  • 5,641
  • 2
  • 27
  • 46
  • Well, thanks for the answer! It worked, but partially. Now the whole action bar with the tabs is moving when I scroll up and down. Any idea why is that, and how to fix it? I'm gonna see what i can do, and if I find a fix, I'll give you the updates. Just to add, i havent done anything different to the default template by android, that's why I'm not uploading any code. – Теодор Митев Oct 06 '16 at 16:26
  • Check this http://stackoverflow.com/questions/6210895/listview-inside-scrollview-is-not-scrolling-on-android – Chisko Oct 06 '16 at 16:26
  • Thanks, I checked it, but couldn't find out why my appbar is moving when I scroll. Any other Ideas? – Теодор Митев Oct 06 '16 at 16:55
1
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

       your content here.........

   </LinearLayout>

</android.support.v4.widget.NestedScrollView>
amaresh hiremani
  • 533
  • 1
  • 8
  • 19