CoordinatorLayout / AppBarLayout ExpandableListView displayed from the screen

Even more problems when using CoordinatorLayout and AppBarLayout.

I am trying to achieve the main functionality of scrolling a toolbar when turning off the screen while scrolling down and returning to the screen when scrolling up.

However, my current setup shows a problem: not only the toolbar does not scroll, as the ListView seems to take the screen below. It is almost as if it were offset by the height of the AppBarLayout.

Here is the gif describing the problem, note that the last item is disabled and the ScrollBar is disabled:

enter image description here

My layout is pretty standard:

<?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:background="@color/background"> <android.support.design.widget.AppBarLayout android:layout_width="match_parent" android:layout_height="wrap_content"> <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?android:attr/actionBarSize" android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" android:background="@color/orange" app:layout_scrollFlags="scroll|enterAlways"/> </android.support.design.widget.AppBarLayout> <android.support.v4.widget.SwipeRefreshLayout android:id="@+id/swipeToRefresh" android:layout_width="match_parent" android:layout_height="match_parent" app:layout_behavior="@string/appbar_scrolling_view_behavior"> <ExpandableListView android:id="@+id/listView" android:groupIndicator="@android:color/transparent" android:layout_width="match_parent" android:dividerHeight="0px" android:layout_height="match_parent"/> </android.support.v4.widget.SwipeRefreshLayout> </android.support.design.widget.CoordinatorLayout> 
+7
android android-coordinatorlayout android-appbarlayout
source share
3 answers

The Layout coordinator only works with RecyclerView or NestedScrollView.Try Wrap your ExapandableListView inside a NestedScrollView or use the code below to make NestedScrollingEnable for an ExpandableListView.

 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { expandablelistView.setNestedScrollingEnabled(true); }else { CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) mSwipeLayout.getLayoutParams(); params.bottomMargin = heightOfAppBarCompat; mSwipeLayout.setLayoutParams(params); } 

Change You can scroll as expected to 21 with the else statement.

+8
source share

I would write this as a comment, but in terms of readability, I will discard this information as an answer. If this does not work, let me know and I will remove it ... I think you should tell your toolbar how to interact. In my application, the toolbar looks like this:

 <android.support.v7.widget.Toolbar android:id="@+id/anim_toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" app:layout_collapseMode="pin" app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/> 

note the "app: layout_collapseMode"

0
source share
 private int mPreviousVisibleItem; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { expListView.setNestedScrollingEnabled(true); } else { expListView.setOnScrollListener(new AbsListView.OnScrollListener() { @Override public void onScrollStateChanged(AbsListView view, int scrollState) { } @Override public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { if (firstVisibleItem > mPreviousVisibleItem) { appBarLayout.setExpanded(false, true); } else if (firstVisibleItem < mPreviousVisibleItem) { appBarLayout.setExpanded(true, true); } mPreviousVisibleItem = firstVisibleItem; } }); } 
0
source share

All Articles