0

I have a very annoying problem with the typical CoordinatorLayout + AppBarLayout + Toolbar + TabLayout + Viewpager where the Toolbar has the layout_scrollFlags with "scroll|enterAlways|snap"

Here is the xml which also has a DrawerLayout with a NavigationView in it:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/activity_tabs_main_drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

    <android.support.design.widget.CoordinatorLayout
        android:id="@+id/activity_tabs_main_coordinator_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.design.widget.AppBarLayout
            android:id="@+id/activity_tabs_main_appbar_layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <android.support.v7.widget.Toolbar
                xmlns:android="http://schemas.android.com/apk/res/android"
                xmlns:app="http://schemas.android.com/apk/res-auto"
                android:id="@+id/material_toolbar"
                style="@style/AppCompatTheme.Toolbar"
                app:layout_scrollFlags="scroll|enterAlways|snap"
                app:popupTheme="@style/material_toolbar_popup"/>

            <android.support.design.widget.TabLayout
                android:id="@+id/activity_tabs_main_tab_layout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:tabIndicatorColor="@color/neon_green"/>
        </android.support.design.widget.AppBarLayout>

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

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

    <android.support.design.widget.NavigationView
        android:id="@+id/navigation_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        app:menu="@menu/drawer_item"/>

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

The real two issues that I notice is that I can swipe the tabs in viewpager in a diagonal way (see image attached) while in Google Play app or Whatsapp or Cheesesquare by Chris Bane if I try to do a Diagonal swipe the RecyclerView take the gesture first and scrolls down/up.

ViewPager Toolbar Bounce bugs

I think this ViewPager's behavior make the Toolbar create a little bounce where the Navigator Drawer Icon is set, next to the Toolbat Title.

So the real problem is trying to prevent this Bounce issue or bug, you can also check this video

Youtube Link: Video to show the bounce effect in the Toolbar

I already tried by removing the DrawerLayout and NavigationView but has no effect, the bounce problem continues.

Thanks in advance!

Nicolas Jafelle
  • 2,661
  • 2
  • 24
  • 30

1 Answers1

0

I think I found a solution to this problem. After adding a View.OnClickListener() inside the RecyclerView.ViewHolder it is almost imperceptible, could be possible?

Here is the code inside the RecyclerView:

    private RecyclerOnItemClickListener itemClickListener;

    class PostDtoViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {

        private final PostView postView;

        public PostDtoViewHolder(PostView postView) {
            super(postView);
            this.postView = postView;
            this.postView.setOnClickListener(this);
        }

        public View getViewHolder() {
            return this.postView;
        }

        public void bind(PostDto postDto) {
            postView.loadContent(postDto);
        }

        @Override
        public void onClick(View v) {
            itemClickListener.onItemClickListener(getAdapterPosition());
        }
    }

Where RecyclerOnItemClickListener is just an interface with the method:

public interface RecyclerOnItemClickListener {

    void onItemClickListener(int itemPosition);
}
Nicolas Jafelle
  • 2,661
  • 2
  • 24
  • 30