【问题标题】:TabLayout inside Toolbar工具栏内的 TabLayout
【发布时间】:2015-09-17 14:51:30
【问题描述】:

我想通过新的设计支持库实现某种外观,但我无法停止看到一个奇怪的错误。

这里是 the screencast with the desired output(未使用 DSL) 还有the ouput I get using DSL

工具栏+选项卡位于带有 viewpager 的 Activity 中,而 recyclerView 位于 viewpager 内的片段内(实际上是适配器,但你明白我的意思)

活动代码:

<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:fab="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <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/toolbar_main"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:elevation="4dp"
            app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
            app:layout_scrollFlags="scroll|enterAlways">

            <android.support.design.widget.TabLayout
                android:id="@+id/tabs"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:tabIndicatorColor="@color/white"
                app:tabTextColor="@color/selected_text"
                app:tabSelectedTextColor="@color/white"/>

        </android.support.v7.widget.Toolbar>

    </android.support.design.widget.AppBarLayout>

    <android.support.v4.view.ViewPager
        android:id="@+id/main_pager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

    <android.support.design.widget.SupportFloatingActionsMenu
           ...>
           /* Code for a fancy fab w/ menu */

    </android.support.design.widget.SupportFloatingActionsMenu>

</android.support.design.widget.CoordinatorLayout>

对于包含 recyclerView 的片段:

<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.insa.burnd.view.MainActivity.NewsfeedFragment"
    android:id="@+id/fragment_newsfeed">

    <android.support.v4.widget.SwipeRefreshLayout
        android:id="@+id/swipe_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <android.support.v7.widget.RecyclerView
            android:id="@+id/recyclerView"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

    </android.support.v4.widget.SwipeRefreshLayout>

</android.support.design.widget.CoordinatorLayout>

java 代码非常标准,我将 viewpager 绑定到选项卡...等等。

提前感谢您的帮助:)!

【问题讨论】:

  • 当您从片段布局中删除CoordinatorLayoutSwipeRefreshLayout 时,有什么变化吗?
  • 我遇到了同样的故障。
  • 你能用新发布的version 22.2.1再试一次吗?
  • 像魅力一样工作!你们太棒了:)!
  • 你在这里问了同样的问题/代码:stackoverflow.com/questions/31161965/….

标签: android android-fragments androiddesignsupport android-tablayout


【解决方案1】:

这个和许多其他错误修复已在设计库的version 22.2.1 中修复。请确保您的 build.gradle 文件引用了最新版本。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-13
    • 2016-10-23
    • 1970-01-01
    • 1970-01-01
    • 2016-01-05
    相关资源
    最近更新 更多