Reputation: 487
My app's action bar consists of a toolbar and a tab view with a ViewPager to display the page's content. I am trying to use a CoordinatorLayout as my root view instead of a LinearLayout, but when I replace LinearLayout
with android.support.design.widget.CoordinatorLayout
, the content with my ViewPager is no longer visible. Here is the XML with LinearLayout
as root:
<LinearLayout 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:orientation="vertical">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:id="@+id/tool_bar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:fitsSystemWindows="true"
app:contentInsetEnd="0dp"
app:contentInsetStart="0dp"
app:layout_scrollFlags="scroll|enterAlways">
<include layout="@layout/actionbar" />
</android.support.v7.widget.Toolbar>
<com.whatsgoodly.views.SlidingTabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/blue" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context=".MainActivity" />
</LinearLayout>
Here is a screenshot of the app with android.support.design.widget.CoordinatorLayout
as the root view. As you can see, the content in the ViewPager is hidden/missing. (I photoshopped out the tab icons and action bar text)
What am I doing wrong?
Upvotes: 0
Views: 1529
Reputation: 982
maybe my one helps you. just customize the content:
<?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"
tools:context=".Activity">
<LinearLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@color/primary_dark"
android:theme="@style/toolbarstyle"/>
<android.support.design.widget.TabLayout
android:id="@+id/sliding_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="scrollable" />
<include layout="@layout/toolbar_shadow" />
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="0px"
android:layout_weight="1"
android:background="@color/white" />
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
Upvotes: 3