ViewPager没有显示出来与CoordinatorLayout [英] ViewPager not showing up with CoordinatorLayout

本文介绍了ViewPager没有显示出来与CoordinatorLayout的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序的操作栏包含一个工具栏和一个ViewPager标签视图来显示页面的内容。我试图用一个CoordinatorLayout作为我的根视图,而不是一个的LinearLayout,但是当我把的LinearLayout android.support.design.widget.CoordinatorLayout ,我ViewPager内容不再可见。这里是的LinearLayout 为根的XML:

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>

下面是应用程序与 android.support.design.widget.CoordinatorLayout 截图作为根视图。正如你所看到的,在ViewPager内容是隐藏/丢失。 (我Photoshop处理出来的标签图标和操作栏文本)

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)

在这里输入的形象描述

我在做什么错了?

推荐答案

也许我的人帮助你。刚刚定制的内容:

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> 

这篇关于ViewPager没有显示出来与CoordinatorLayout的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆