2

I am working on this environment,

compileSdkVersion 25
    buildToolsVersion '25.0.0'
    defaultConfig {
        minSdkVersion 21
        targetSdkVersion 25

with these dependencies:

compile 'com.android.support:appcompat-v7:25.0.1'
    compile 'com.android.support:design:25.0.1'
    compile 'com.android.support:recyclerview-v7:25.0.1'
    compile 'com.android.support:cardview-v7:25.0.1'

I want to make a view with a coordinatorlayout but containing a viewPager, not a recyclerview. this is the layout file:

<?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.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|enterAlways"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

        <android.support.design.widget.TabLayout
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="72dp"
            app:tabGravity="fill"
            app:tabMode="fixed" />
    </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>

My problem is that the scroll doesn't work for the view. I see some posts that implementing the onTouch method to simulate the scroll, but i want to work with the coordinatorLayout. Thanks.

Fakher
  • 2,098
  • 3
  • 29
  • 45
  • What layouts do you need coordinated here? In other words, what is wrong with LinearLayout, for example? – OneCricketeer Dec 04 '16 at 00:53
  • Are you trying to do this? https://gist.github.com/iPaulPro/1468510f046cb10c51ea#gistcomment-1471485 You are missing a CollapsingToolbarLayout – OneCricketeer Dec 04 '16 at 00:57
  • yes i'm trying to do this but the pager that i have doesn't contain a recyclerview, it contain LinearLayout that contain components. – Fakher Dec 05 '16 at 08:32
  • Okay, so you have a LinearLayout that isn't scrolling? And why is it that a problem? LinearLayout doesn't scroll. Regardless of a ViewPager. You need a Scrollview – OneCricketeer Dec 05 '16 at 14:38

2 Answers2

7

To work with CoordinatorLayout it needs a View that implements NestedScrollingChild interface inside the ViewPager, like NestedScrollView. So, nest your LinearLayout as child of a NestedScrollView.

GPack
  • 2,494
  • 4
  • 19
  • 50
6
<androidx.core.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true"
    app:layout_behavior="@string/appbar_scrolling_view_behavior" >
    
    <android.support.v4.view.ViewPager
        android:id="@+id/viewpager"
        android:layout_width="match_parent"
        android:layout_height="200dp"/>

<!--Wrap content will not work here you have to give fix height-->

</androidx.core.widget.NestedScrollView>
Boken
  • 4,825
  • 10
  • 32
  • 42
Rajesh
  • 2,618
  • 19
  • 25