How to set the footer inside the CoordinatorLayout correctly

I will talk more about this in more detail.

Android - footer scrolls from screen when used in CoordinatorLayout

and

https://code.google.com/p/android/issues/detail?id=177195

I want to hide TabLayout while scrolling on a RecyclerView . That is why I have the following layout.

 <CoordinatorLayout> <CollapsingToolbarLayout> <TabLayout> <ViewPager> <RecyclerView> <Footer> 

In my situation, I have a ViewPager that contains several fragments.

Most snippets contain a RecyclerView and a footer. They look as follows

 <LinearLayout> <RecyclerView /> <LinearLayout id="@+id/footer" /> </LinearLayout> 

Unfortunately, the footer can be moved while scrolling, although I would like it to be static.

Please note: it is important that app:layout_behavior placed in the ViewPager instead of the RecyclerView . If not, TabLayout will not appear.

My implementation is as follows

my_fragment.xml

 <?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:id="@+id/coordinator_layout" android:layout_width="match_parent" android:layout_height="match_parent" > <android.support.design.widget.AppBarLayout android:id="@+id/app_bar_layout" android:layout_width="match_parent" android:layout_height="wrap_content" android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" > <android.support.design.widget.CollapsingToolbarLayout android:layout_width="match_parent" android:layout_height="wrap_content" app:layout_scrollFlags="scroll|enterAlways|snap"> <android.support.design.widget.TabLayout android:id="@+id/tab_layout" android:layout_width="match_parent" android:layout_height="wrap_content" app:tabIndicatorColor="?attr/portfolioTabIndicatorColor" /> </android.support.design.widget.CollapsingToolbarLayout> </android.support.design.widget.AppBarLayout> <android.support.v4.view.ViewPager android:id="@+id/view_pager" android:layout_width="match_parent" android:layout_height="match_parent" app:layout_behavior="org.yccheok.xxx.CustomScrollingViewBehavior" /> </android.support.design.widget.CoordinatorLayout> 

The most key class is org.yccheok.xxx.CustomScrollingViewBehavior , which is copied and pasted from https://stackoverflow.com/a/3/4/2/2/16

org.yccheok.xxx.CustomScrollingViewBehavior is the best solution I can find so far. However, it is far from ideal, as it gives the following behavior.

This causes flickering when you scroll a little and release your finger. Please refer to the following video.

https://youtu.be/8RvCZJeQvS0

I was wondering, based on the proposed solution on https://stackoverflow.com/a/3/9/12/16/16/ , is there any further improvement in the CustomScrollingViewBehavior class to avoid a flickering effect?

+1
android
Mar 19 '16 at 5:46
source share
1 answer

I was able to achieve what I want, following the leadership in

https://mzgreen.imtqy.com/2015/02/15/How-to-hideshow-Toolbar-when-list-is-scroling%28part1%29/

http://mzgreen.imtqy.com/2015/02/28/How-to-hideshow-Toolbar-when-list-is-scrolling%28part2%29/

The key ideas are

  • Do not use CoordinatorLayout
  • Place the TabLayout and RecyclerView within the FrameLayout so that the TabLayout will overlap on top of the RecyclerView
  • Add top add-on to RecyclerView . It matters android:clipToPadding="false" .
  • To hide / show the TabLayout while scrolling, add the HidingScrollListener to the RecyclerView .

The disadvantage of this solution is that requiresFadingEdge will no longer work on RecyclerView due to the top fill.

+1
Mar 21 '16 at 2:15
source share



All Articles