ViewPager not showing up with CoordinatorLayout

一个人想着一个人 提交于 2019-12-08 09:01:35

问题


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?


回答1:


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> 


来源:https://stackoverflow.com/questions/32661137/viewpager-not-showing-up-with-coordinatorlayout

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!