Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Viewpager not scrolling in Coordinator layout

This is my layout

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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:fitsSystemWindows="true">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="280dp"
        android:fitsSystemWindows="true"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapse_toolbar"
            android:layout_width="match_parent"
            android:layout_height="250dp"
            android:fitsSystemWindows="true"
            app:contentScrim="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="100dp"
                android:gravity="top"
                android:minHeight="?attr/actionBarSize"
                app:layout_collapseMode="pin"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
                app:titleMarginTop="15dp">

            </android.support.v7.widget.Toolbar>

            <android.support.design.widget.TabLayout
                android:id="@+id/category_tabs"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:layout_gravity="bottom"
                android:background="#f0f0f0"
                android:focusable="false" />

            <View
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:background="@color/talview_color_1" />

        </android.support.design.widget.CollapsingToolbarLayout>

    </android.support.design.widget.AppBarLayout>

    <android.support.v4.view.ViewPager
        android:id="@+id/pager"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />  

</android.support.design.widget.CoordinatorLayout>

I am trying to pin the tablayout on top while scrolling. It doesn't work. More important point is, there is a listview in each viewpager fragment and the listview scrolling doesn't work in the listview.

Can anybody help

like image 246
shreyas Avatar asked Dec 18 '15 13:12

shreyas


People also ask

Is ViewPager scrollable?

Androidx Auto Scroll ViewPager ViewPager which can auto scrolling, cycling, decelerating. ViewPager which can be slided manually in parent ViewPager. ViewPager which is compatible with AndroidX library.

How do you align items in coordinator layout?

You can try gravity to align inside the CoordinatorLayout. android:layout_gravity="end" This worked for me. Save this answer. Show activity on this post.

What is the function of a ViewPager?

ViewPager in Android allows the user to flip left and right through pages of data. In our android ViewPager application we'll implement a ViewPager that swipes through three views with different images and texts.


1 Answers

You need to use NestedScrollView, provided in Android Support Library v4, which is designed to work with CoordinatorLayout

<android.support.v4.widget.NestedScrollView ...>
    <LinearLayout ...>
        ...
    </LinearLayout>
</android.support.v4.widget.NestedScrollView>

or RecyclerView, please note that the classic ListView doesn't work with CoordinatorLayout.

so inside your viewPager you need to have NestedScrollView or RecyclerView

Good luck

like image 71
Netero Avatar answered Sep 24 '22 22:09

Netero