首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >CoordinatorLayout滚动处理故障

CoordinatorLayout滚动处理故障
EN

Stack Overflow用户
提问于 2016-08-12 00:00:51
回答 1查看 79关注 0票数 0

我有一个包含工具栏和RecyclerView的CoordinatorLayout。我已经配置了布局,当用户滚动RecyclerView时,工具栏会缩小和隐藏。这可以很好地工作。除非RecyclerView的单元格(行)本身包含水平滚动的RecyclerViews。当我点击这样的单元格并向上滚动时,工具栏不会隐藏。似乎CoordinatorLayout处理这些单元格的滚动事件,并且不知何故被弄糊涂了。有没有办法解决这个问题?

这是我的布局:

代码语言:javascript
复制
<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/main.appbar"
      android:layout_width="match_parent"
      android:layout_height="wrap_content">

      <android.support.v7.widget.Toolbar
          android:id="@+id/main.toolbar"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          app:layout_scrollFlags="scroll|enterAlways">

          <Button
              android:id="@+id/button1"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="Button 1" />

          <Button
              android:id="@+id/button2"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="Button 2" />
      </android.support.v7.widget.Toolbar>
  </android.support.design.widget.AppBarLayout>

  <RelativeLayout
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:background="@android:color/white"
      android:paddingBottom="0pt"
      android:paddingLeft="0pt"
      android:paddingRight="0pt"
      android:paddingTop="0pt"
      app:layout_behavior="@string/appbar_scrolling_view_behavior">

      <android.support.v7.widget.RecyclerView
          android:id="@+id/recyclerView"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:layout_alignParentBottom="true"
          android:layout_alignParentEnd="true"
          android:layout_alignParentLeft="true"
          android:layout_alignParentRight="true"
          android:layout_alignParentStart="true"
          android:layout_alignParentTop="true">
      </android.support.v7.widget.RecyclerView>

  </RelativeLayout>

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

回答 1

Stack Overflow用户

发布于 2016-08-12 00:09:04

在我提出这个问题后不久,我在网上找到了答案。

https://stackoverflow.com/a/32975317/1036017

本质上,对于任何包含水平滚动RecyclerView的单元格,我们必须禁用嵌套滚动。下面是这样一个单元格的布局示例。我们将android:nestedScrollingEnabled属性设置为false。

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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="250dp">

    <android.support.v7.widget.RecyclerView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/recyclerView"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        android:nestedScrollingEnabled="false">
    </android.support.v7.widget.RecyclerView>

    <ImageView
        android:layout_width="30dp"
        android:layout_height="30dp"
        android:layout_centerVertical="true"
        android:layout_alignParentLeft="true"
        app:srcCompat="@drawable/left_chevron"
        android:id="@+id/leftArrow" />

    <ImageView
        android:layout_width="30dp"
        android:layout_height="30dp"
        android:layout_centerVertical="true"
        android:layout_alignParentRight="true"
        app:srcCompat="@drawable/right_chevron"
        android:id="@+id/rightArrow" />
</RelativeLayout>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38901191

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档