I have an app with a coordinator layout that uses sliding tabs and a view pager in a coordinator layout. I am trying to place an activity (list) below the toolbar. I have tried a number of different things but always the list overlaps the toolbar.
Layout
<?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"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:fitsSystemWindows="true"
tools:context=".MainActivity">
<LinearLayout 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="wrap_content"
android:orientation="vertical" >
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:fitsSystemWindows="true"
android:minHeight="?attr/actionBarSize"
android:padding="2dp"
app:titleMarginStart="20dp"
android:theme="@style/AppTheme.AppBarOverlay"/>
<com.passwordstore.utility.SlidingTabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary" />
<View
android:layout_width="match_parent"
android:layout_height="4dp"
android:background="@android:color/white"
android:foreground="@drawable/shadow"/>
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
</android.support.v4.view.ViewPager>
</LinearLayout>
<FrameLayout android:layout_width="match_parent" android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" android:id="@+id/frameLayout">
<include layout="@layout/activity_password_list" />
</FrameLayout>
<android.support.design.widget.FloatingActionButton android:id="@+id/fabNew"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_margin="@dimen/fab_margin" android:src="@drawable/ic_add_white_24dp"
app:layout_anchor="@+id/pager"
app:layout_anchorGravity="bottom|right|end"/>
</android.support.design.widget.CoordinatorLayout>
CoordinatorLayout is a super-powered FrameLayout . CoordinatorLayout is intended for two primary use cases: As a top-level application decor or chrome layout. As a container for a specific interaction with one or more child views.
You can define ToolBar custom layout using constraint layout as shown below, see http://www.zoftino.com/android-toolbar-tutorial for more information. Show activity on this post. This is an example of where the answer should display the important stuff from the links, in case links stops working.
The CoordinatorLayout. DefaultBehavior annotation is deprecated.
Just add app:layout_behavior="@string/appbar_scrolling_view_behavior"
to the layout that needs to be under the toolbar
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With