android.support.v7.widget.Toolbar
seems to push the content to the bottom, check out these screenshots:
This screen is the original state when switching to the fragment:
After scrolling down a little bit I can see the full layout:
So how can I prevent the scrolling? If I remove android.support.v7.widget.Toolbar
from the xml code everything works as expected (except for the missing toolbar lol).
This is the code of the main activity:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout android:id="@+id/main_content"
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"
tools:context=".activity.MainActivity">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="@dimen/appbar_padding_top"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/AppTheme.PopupOverlay" />
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_margin="@dimen/fab_margin"
android:src="@android:drawable/ic_menu_add"/>
</android.support.design.widget.CoordinatorLayout>
And heres the code of the chat fragment:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<android.support.v7.widget.RecyclerView
android:id="@+id/list"
android:scrollbars="vertical"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:divider="@null"
android:stackFromBottom="true"
android:transcriptMode="normal" />
<LinearLayout
android:id="@+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#ffffff"
android:orientation="horizontal"
android:padding="2dp" >
<EditText
android:id="@+id/enter_message"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:layout_weight="0.85"
android:hint="hint"
android:inputType="textCapSentences|textMultiLine"
android:maxLines="5" />
<Button
android:id="@+id/send_button"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="center"
android:layout_marginRight="5dp"
android:background="@drawable/common_google_signin_btn_icon_dark_normal" />
</LinearLayout>
</LinearLayout>
Removing android:fitsSystemWindows="true"
, as suggested in other threads, didn't change anything. Thanks in advance!
I’m not sure I got your desired behavior. You probably want to leave the layout as is but just remove the scroll flags from the toolbar:
app:layout_scrollFlags="scroll|enterAlways"
These flags tell the toolbar to listen to scrolls on the recycler view and react accordingly. As I understand, you want the toolbar to stay fixed. So, remove that line.