【问题标题】:Toolbar not hiding with Coordinator Layout工具栏不与协调器布局一起隐藏
【发布时间】:2015-08-26 12:30:50
【问题描述】:

我正在尝试复制this blog post 中讨论的行为,当我向下滚动 RecyclerView(在单独的片段中)时,工具栏将隐藏,标签保留。

不幸的是,在玩了很多之后,我似乎无法让工具栏移动,而是保持静止。我已经为我的活动和片段附加了 XML。

感谢您的帮助,如果您需要更多代码,请询问!

活动

<?xml version="1.0" encoding="utf-8"?>

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/drawerLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.design.widget.CoordinatorLayout 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="match_parent">

        <android.support.design.widget.AppBarLayout
            android:id="@+id/appBarLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <android.support.v7.widget.Toolbar
                android:id="@+id/topToolbar"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="?attr/colorPrimary"
                android:minHeight="?attr/actionBarSize"
                app:layout_scrollFlags="scroll|enterAlways" />

            <android.support.design.widget.TabLayout
                android:id="@+id/tabLayout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="?attr/colorPrimary" />

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

        <android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/mainPager"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

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

    <android.support.design.widget.NavigationView
        android:id="@+id/navigationView"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        app:menu="@menu/navigation_drawer_menu" />

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

片段:

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout 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="info.test.redditclient.Fragment_Posts">

    <android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/swipe_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

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

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

    <TextView
        android:id="@+id/no_posts_text"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:gravity="center"
        android:text="@string/no_posts"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:visibility="gone" />

    <fragment
        android:id="@+id/bottom_toolbar"
        android:name="info.test.redditclient.Fragment_Bottom_Toolbar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        tools:layout="@layout/fragment_bottom_toolbar"></fragment>

</RelativeLayout>

编辑:

在一些建议之后,对于我的活动布局,我已将 viewpager 移到 AppBarLayout 之外,并且还删除了一个多余的框架布局。问题依然存在。

【问题讨论】:

  • 您是否将片段添加到 ID 为“容器”的框架布局?
  • 抱歉,不。那是我的 NavigationDrawer 的容器。使用我的自定义寻呼机适配器添加片段

标签: android android-fragments


【解决方案1】:

将视图分页器移到 AppBarLayout 之外

【讨论】:

  • 谢谢,那绝对不应该在那里。但是,它并没有解决我的问题。它实际上已将我的 FAB 从另一个片段移到屏幕之外。 i.imgur.com/UvBu4CQ.png.
【解决方案2】:

问题已解决:

我使用的是 22.2.0 之前的 RecyclerView,它不起作用。

我通过更改 Gradle 构建解决了这个问题:

compile 'com.android.support:recyclerview-v7:22.2.0'

【讨论】:

  • 23.0.0 是最新的。
猜你喜欢
  • 2016-07-26
  • 1970-01-01
  • 1970-01-01
  • 2017-04-21
  • 2020-12-11
  • 1970-01-01
  • 1970-01-01
  • 2019-04-28
  • 1970-01-01
相关资源
最近更新 更多