Search code examples
listviewandroid-fragmentsandroid-viewpagerandroid-coordinatorlayout

listview inside fragment within tablayout + coordinatorlayout doesn't scroll


The ListView below doesn't scroll. It uses the ViewPager component from the first layout. The Fragments for the ViewPager are brought in dynamically. The onScroll event of the ListView works with loading 100 items but scrolling doesn't work. Can anyone see sometj

I've got the following xml layout:

    <android.support.design.widget.CoordinatorLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    android:background="@color/background_primary"
    >
    <android.support.design.widget.AppBarLayout
        android:id="@+id/abl_main"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/text_header_field"
        app:theme="@style/MyMaterialTheme"
        >
        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="@color/text_header_field"
            app:layout_scrollFlags="scroll|enterAlways"
            android:padding="0dp"
            app:contentInsetLeft="0dp"
            app:contentInsetRight="0dp"
            app:contentInsetStart="0dp"
            app:popupTheme="@style/CDTheme.NoActionBar.PopupOverlay"
            >
            <com.cashdash.views.components.TypefaceTextView
                android:id="@+id/toolbar_title"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                app:customTypeface="fonts/Montserrat-Light.otf"
                android:layout_gravity="center"
                android:textSize="16sp"
                android:text="@string/title_activity_transaction"
                android:gravity="center"
                android:textColor="@color/text_title"
                android:textAllCaps="true"
                android:background="@color/text_header_field"
                />
        </android.support.v7.widget.Toolbar>
        <android.support.design.widget.TabLayout
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:tabIndicatorColor="@color/background_primary_to"
            app:tabBackground="@color/text_header_field"
            app:tabMode="fixed"
            app:tabGravity="fill"
            app:tabSelectedTextColor="@color/field_value_dark"
            app:tabTextColor="@color/tab_inactive"
            />
    </android.support.design.widget.AppBarLayout>
    <android.support.v4.view.ViewPager
        android:id="@+id/viewpager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"  />
</android.support.design.widget.CoordinatorLayout>

This is the Fragment:

    <FrameLayout
     xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:tools="http://schemas.android.com/tools"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     tools:context=".TransactionHistoryFragment"
     android:background="@color/background_primary">
     <ListView
            android:id="@+id/lv_transaction"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fillViewport="true"
        />
   </FrameLayout>

Update:

I've tried several things and the 'merge' of these solved the problem. Generally, it was an issue of nested scrolling, but the solution was about:

  • intercepting from the parent hierarchy the Touch event and implement scrolling
  • using the xml attribute android:nestedScrollingEnabled="true" for API 21+
  • using the page transformation on the ViewPager as was brought as an optional solution

Each by its own was an integral part of the solution.


Solution

  • The solution is:

    • intercepting from the parent hierarchy the Touch event and implement scrolling
    • using the xml attribute android:nestedScrollingEnabled="true" for API 21+
    • using the page transformation on the ViewPager as was brought as an optional solution

    Currently, there is no solution for API 20-, other than construct the whole view in different manner.