henrytao-me / smooth-app-bar-layout

Smooth version of Google Support Design AppBarLayout
Apache License 2.0
1.77k stars 240 forks source link

ViewPager not scrolling? #50

Closed ghost closed 8 years ago

ghost commented 8 years ago

Hello, first of all thank you for this improvement of AppBarLayout. I managed to create a simple activity with collapsing toolbar and a nestedscrollview under it. I have encountered a problem when using tablayout: everything is setted fine, but when i scroll a fragment (tab) the AppBarLayout remains expanded, static. What do i have to change when passing from AppBarLayout to SmoothAppBarLayout in case of Tablayout? Thank you and sorry for my bad english

henrytao-me commented 8 years ago

Can you post your layout here?

ghost commented 8 years ago

Here: sorry for the delay

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <android.support.v4.view.ViewPager
        android:id="@+id/viewPager"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <me.henrytao.smoothappbarlayout.SmoothAppBarLayout
        android:layout_width="match_parent"
        android:layout_height="250dp">

        <android.support.design.widget.CollapsingToolbarLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:contentScrim="@color/primary"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">

            <ImageView
                android:id="@+id/cover"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@drawable/img1"
                android:scaleType="centerCrop"
                app:layout_collapseMode="parallax" />

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="104dp"
                android:background="@android:color/transparent"
                android:gravity="top"
                android:minHeight="?attr/actionBarSize"
                app:layout_collapseMode="pin"
                app:titleMarginTop="13dp" />

            <android.support.design.widget.TabLayout
                android:id="@+id/tabLayout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="bottom" />

        </android.support.design.widget.CollapsingToolbarLayout>
    </me.henrytao.smoothappbarlayout.SmoothAppBarLayout>
</android.support.design.widget.CoordinatorLayout>

With stock appbarlayout and the layout_behavior for viewpager it works well, like this it seems like the viewpager isn't synchronized with smoothappbarlayout

P.S. there is a coordinatorlayout not shown :S

henrytao-me commented 8 years ago

Hi, I have a fever and in hospital now. It may take few more days. Sorry about it.

ghost commented 8 years ago

Oh , I'm sorry! I will be waiting :D

henrytao-me commented 8 years ago

Hi @narger17 Can you provide more information about your project? Ex: device info, api version. Your layout looks quite the same with this layout fragment_smooth_view_pager_parallax.xml. Can you also look into fragment implementation too? SmoothViewPagerParallaxFragment.java

ghost commented 8 years ago

My device is a Nexus 5 with Android M and the project is setted up this way: min sdk level : 15 target/compile sdk level : 23 main activity theme : Theme.AppCompat.Light.NoActionBar

public class MainActivity extends AppCompatActivity { ...

public void TabsSetUp() { ViewPager viewPager = (ViewPager) findViewById(R.id.viewPager); TabLayout tabLayout = (TabLayout) findViewById(R.id.tabLayout); ((CollapsingToolbarLayout) findViewById(R.id.collapsingToolbar)).setTitleEnabled(false);

    ViewPagerRunnableAdapter adapter = new ViewPagerRunnableAdapter(getSupportFragmentManager());

    adapter.addFragment(new DummyFragment(), "Page1");
    adapter.addFragment(new DummyFragment(), "Page2");
    adapter.addFragment(new DummyFragment(), "Page3");

    if (adapter instanceof PagerAdapter) {
        viewPager.setAdapter(adapter);
    }

    tabLayout.setupWithViewPager(viewPager);
    tabLayout.setSelectedTabIndicatorColor(Color.RED);

}

ViewPagerRunnableAdapter and BaseViewPagerAdapter are copied from your sample project :P Thank you!

ghost commented 8 years ago

I made it ! I forgot to implement ObservableScrollView to DummyFragment ! :D thank you anyway !