CoordinatorLayout不起作用 [英] CoordinatorLayout not working

查看:110
本文介绍了CoordinatorLayout不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从新发布的CoordinatorLayout ="noreferrer"> Android设计支持库,根据示例

I am attempting to implement a CoordinatorLayout from the newly announced Android Design Support Library and I have used the following code in my XML layout as per the sample here:

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/main_content"
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:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        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"/>

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

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

但是,当我向下滚动视图时,操作栏不会隐藏.我不知道为什么这不起作用.

However the action bar does not hide when I scroll down the view. I can't figure out why this is not working.

据我所知,CoordinatorLayout不适用于ListView/GridView/ScrollViews,而仅适用于RecyclerViewNestedScrollView.不幸的是,对我来说,仅切换到其中一种视图是不可能的,因此我仍在寻找解决方案.

As far as I am aware it appears that CoordinatorLayout does not work with ListView/GridView/ScrollViews and only works with RecyclerView and NestedScrollView. Unfortunately simply switching to one of these views is not a possibility for me so I am still looking for a solution.

推荐答案

我相信您需要使ListView同时实现ScrollingViewNestedScrollingChild接口.

I believe you need to make your ListView implement both ScrollingView and NestedScrollingChild interfaces.

这不是最简单的事情,但是如果您查看RecyclerView的源代码,您应该能够做到.它使用了NestedScrollingChildHelper,您应该可以执行同样的操作.

It's not the easiest thing, but you should be able to do it if you look at RecyclerView's source code. It makes use of a NestedScrollingChildHelper and you should be able to do the same.

这篇关于CoordinatorLayout不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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