8

I'm trying to use a coordinator layout with an appbar layout that hosts a fragment as the "scrolling view". The fragment consists of a recyclerView and a bottom aligned layout holding a button, like so:

enter image description here

However, the bottom section is hidden by default:

enter image description here

and only shows up after I scroll.

From my activity class:

 @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); TestFragment fragment = (TestFragment) getFragmentManager().findFragmentByTag("Test"); if (fragment == null) fragment = new TestFragment(); getFragmentManager().popBackStack(); FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction(); fragmentTransaction.replace(R.id.fragment_container, fragment, "Test"); fragmentTransaction.commit(); } 

Activity layout:

<RelativeLayout 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.support.design.widget.CoordinatorLayout android:id="@+id/main_content" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <FrameLayout android:id="@+id/fragment_container" 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/appbar" android:layout_width="match_parent" android:layout_height="wrap_content" android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> <android.support.design.widget.TabLayout android:id="@+id/tabs" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" app:layout_scrollFlags="enterAlways|scroll" app:tabGravity="fill" app:tabMode="fixed"/> </android.support.design.widget.AppBarLayout> </android.support.design.widget.CoordinatorLayout> </RelativeLayout> 

Fragment layout:

<RelativeLayout 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.support.v7.widget.RecyclerView android:id="@+id/recyclerView" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_above="@+id/bottomView" android:scrollbars="vertical" android:visibility="visible"/> <RelativeLayout android:id="@+id/bottomView" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:background="#d4285d" app:layout_scrollFlags="enterAlways"> <Button android:id="@+id/button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Do something..." android:textSize="14sp"/> </RelativeLayout> </RelativeLayout> 

The end goal here is for the fragment to have the bottom bar always on screen, and the recycler view scrolling the appbar away.

Is this possible?

Thanks all!

2
  • 1
    I have the same problem. I half 'solved' it by putting the 'bottomLayout' in the Activity (and not the Fragment) and outside of the CoordinatorLayout. It now remains visible even when scrolling. However, I also sometimes want to hide it (not when scrolling, but when I press a toolbar button), and in that case the scrolling view (RecyclerView) doesn't fill up the space left behind, instead it remains 'empty' (white). Also, the 'bottomView' appears on top of the scrolling view even though it's outside of the CoordinatorLayout and underneath it in a LinearLayout. I'm confused... Commented Aug 3, 2015 at 11:44
  • Nick, I ended up taking the same approach for the time being, where the bottomLayout is put into the Activity. I handled this in a generic way by adding a FrameLayout to the Activity, which I access from the fragment and add a view in there. It's messy, but I couldn't get around it. I do not have to deal with hiding that bar sometimes (other than hiding it entirely when I switch fragments) so I can't comment on that issue... sorry. Commented Aug 3, 2015 at 17:46

1 Answer 1

3

It seems this is impossible to do at the moment (forever?).

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.