henrytao-me / smooth-app-bar-layout

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

SmoothAppBarLayout overlaps listview #181

Closed ant-ia closed 7 years ago

ant-ia commented 7 years ago

Hi, what is the equivalent of app:layout_behavior="@string/appbar_scrolling_view_behavior" for the smooth library?

ant-ia commented 7 years ago

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"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

    <me.henrytao.smoothappbarlayout.SmoothAppBarLayout
        android:id="@+id/smooth_app_bar_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        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">

            <ImageView
                android:id="@+id/header"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@drawable/image_demo"
                android:fitsSystemWindows="true"
                android:scaleType="centerCrop"
                app:layout_collapseMode="parallax" />

            <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.design.widget.TabLayout
                android:id="@+id/tabs"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:layout_gravity="bottom"
                app:tabMode="scrollable"
                app:tabIndicatorColor="@color/colorAccent" />

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

    </me.henrytao.smoothappbarlayout.SmoothAppBarLayout>

    <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>

If use "app:layout_behavior="@string/appbar_scrolling_view_behavior" i have a lag on scroll

the version of my library is 23.4.0.1 and

henrytao-me commented 7 years ago

Hi @ant-ia

You dont have to specify app:layout_behavior="@string/appbar_scrolling_view_behavior" in order to use SmoothAppBarLayout. Just need to change the order a bit: move ViewPager above SmoothAppBarLayout. Please check the sample here https://github.com/henrytao-me/smooth-app-bar-layout/blob/master/sample/src/main/res/layout/activity_smooth_view_pager_exit_util_collapsed.xml

Thanks,

ant-ia commented 7 years ago

Hi @henrytao-me thanks for answer. But if change the order like you said above, the first elements of the list are covered

henrytao-me commented 7 years ago

With SmoothAppBarLayout, you have to specify the header height of every list which has the same height as SmoothAppBarLayout in order to fix the cover issue.

ant-ia commented 7 years ago

Thanks again for your reply. Only I have the list into another XML file that a fragment. How do I set?

<android.support.v7.widget.RecyclerView android:id="@+id/list" android:layout_width="match_parent" android:layout_height="match_parent" tools:listitem="@layout/list_item_test" />

henrytao-me commented 7 years ago

If you put list into fragment, it won't work with SmoothAppBarLayout in current release version. Sorry for that.

ant-ia commented 7 years ago

Which version might work?

or else what to me to make recommendations? I have still a fragment of tablayout ...

henrytao-me commented 7 years ago

Let me do a test again and let you know soon.

ant-ia commented 7 years ago

Agree! I thank you and I am waiting for your miracle :)

henrytao-me commented 7 years ago

Hi @ant-ia

Please check this branch. I tested fragment with SmoothAppBarLayout (without viewpager), it works. For viewpager, SmoothAppBarLayout supports fragment by default.

https://github.com/henrytao-me/smooth-app-bar-layout/tree/issue-181 https://github.com/henrytao-me/smooth-app-bar-layout/commit/4e414f2174389742f7fc6d8f8693dead06120b0a

Cheers, Henry

ant-ia commented 7 years ago

Hi @henrytao-me . thank for the support.

This it did work! But we still have the same problem with viewpager.

i have the main xml like :

<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"
    android:fitsSystemWindows="true">

    <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.AppBarLayout
        android:id="@+id/smooth_app_bar_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        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">

. . . .

then I have a list that I work in a fragment Class, like this xml:

<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/swipeContainer"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        tools:listitem="@layout/list_item_test"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true" />

</android.support.v4.widget.SwipeRefreshLayout>

        ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager());
        adapter.addFrag(new TestFragment(), "A");
        adapter.addFrag(new TestFragment(), "B");
        adapter.addFrag(new TestFragment(), "C");
        adapter.addFrag(new TestFragment(), "D");

Any fragment that would add to ViewPager ... (Which contains a list or not) is overwritten by the height of SmoothAppBarLayout

henrytao-me commented 7 years ago

Hi @ant-ia

Can you remove layout_behavior in your view_pager? AppBarLayout should be changed to SmoothAppBarLayout. It should be like this

 <android.support.v4.view.ViewPager
        android:id="@+id/viewpager"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
ant-ia commented 7 years ago

I'm sorry, I had copied the unmodified code. In the example it is exactly like you said.

It still does not work

@henrytao-me

henrytao-me commented 7 years ago

Hmmmmmmm. Can you share me the repo or can you be able to share video to illustrate the issue?

ant-ia commented 7 years ago

certainly give me a few minutes you'll make the repo and you share it

ant-ia commented 7 years ago

Hi @henrytao-me

you can download the test repo here:

https://www.dropbox.com/s/hldvzwzvy6d6v19/TestApp.zip?dl=0

henrytao-me commented 7 years ago

Hi @ant-ia

I couldn't run your project unfortunately. It said

Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536

The issue may come from fitSystemWindows. Please try to remove it first and follow exactly this example https://github.com/henrytao-me/smooth-app-bar-layout/blob/master/sample/src/main/res/layout/activity_smooth_view_pager_exit_util_collapsed.xml

I prefer git project rather than zip file because it's easier to track changes. So that, you can see what did I do to fix the issue.

ant-ia commented 7 years ago

i removed fitSystemWindow but not work yet.

Sorry for the exception add

defaultConfig { multiDexEnabled true }

to your app build.gradle file

@henrytao-me