6

I am using Coordinator layout along with NestedScrollView in my fragment for the Collapsing Toolbar animation. I am adding views dynamically to my Nested Scrollview container. I have implemented onClickListener on the views inside NestedScrollView, but the first click on any view is always ignored. When I tap for a second time or more than it works. The code for my XML is as follows:

<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (C) 2015 The Android Open Source Project
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~      http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<android.support.design.widget.CoordinatorLayout
    android:id="@+id/main_content"
    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:fitsSystemWindows="true">

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

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/collapsing_toolbar"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        app:collapsedTitleTextAppearance="@style/toolBarTitleStyle"
        app:contentScrim="@color/primary"
        app:expandedTitleMarginBottom="@dimen/dimen_21dp"
        app:expandedTitleMarginStart="@dimen/dimen_13dp"
        app:expandedTitleTextAppearance="@style/ExpandedToolBarTextTheme"
        app:layout_scrollFlags="scroll|exitUntilCollapsed">

        <ImageView
            android:id="@+id/backdrop"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:fitsSystemWindows="true"
            android:scaleType="centerCrop"
            android:src="@drawable/locality_bg"
            app:layout_collapseMode="parallax"
            app:layout_collapseParallaxMultiplier="0.2"/>

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:layout_collapseMode="pin"/>

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

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

<android.support.v4.widget.NestedScrollView
    android:id="@+id/scroll_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <LinearLayout
        android:id="@+id/base_view_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/black_20pc"
        android:orientation="vertical">

    </LinearLayout>

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

<com.locon.housing.views.RobotoMediumButton
    android:id="@+id/view_listings"
    android:layout_width="match_parent"
    android:layout_height="@dimen/dimen_56dp"
    android:layout_gravity="bottom"
    android:background="@color/vida_loca"
    android:gravity="center"
    android:text="@string/alerts_view_listings"
    android:textColor="@color/white"
    android:textSize="@dimen/fontsize_medium"/>

<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab_button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_margin="@dimen/dimen_16dp"
    android:clickable="true"
    android:src="@drawable/ic_action_new"/>

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

It seems like NestedScrollView is intercepting the touch event and not passing to a child for the first time. How do I fix this issue?

Roman Melnyk
  • 1,097
  • 1
  • 8
  • 21
  • Have you tried to extends `AppBarLayoutBehavior` and override onInterceptTouchEvent and `return false` on the `target` views that should not trigger nested scroll, so they can consume the events without triggering the nested scroll? – Nikola Despotoski Sep 27 '15 at 12:57
  • @NikolaDespotoski I am adding views dynamically to NestedScrollView, so I don't whether it will work. I tried to add a custom app:layout_behavior but it is giving me an exception : java.lang.RuntimeException: Could not inflate Behavior subclass. Can you provide some example of what you trying to say? – Akshit Chhabra Sep 27 '15 at 18:10
  • 3
    Got it. The issue is due to a bug in android support library (23.0.1) NestedScrollView. It can be found here : https://code.google.com/p/android/issues/detail?id=178041 This issue will most probably be fixed in next release. Till then you can see the workaround from this post : http://stackoverflow.com/a/32783524/1999153 – Akshit Chhabra Sep 28 '15 at 10:07

2 Answers2

2

I have the same bug. After upgrading support library version to 27.0.1 bug has been disappeared.

See: https://developer.android.com/topic/libraries/support-library/revisions.html#27-0-1

After a user scrolls, they cannot click on an item in a RecyclerView. (AOSP issue 66996774)

See the same question: Android - the item inside RecyclerView can't be clicked after scroll

  • 2
    A link to a solution is welcome, but please ensure your answer is useful without it: [add context around the link](//meta.stackexchange.com/a/8259) so your fellow users will have some idea what it is and why it’s there, then quote the most relevant part of the page you're linking to in case the target page is unavailable. [Answers that are little more than a link may be deleted.](//stackoverflow.com/help/deleted-answers) – Filnor Dec 19 '17 at 14:49
1

If u using androidX: upgrade to 1.1.0 version of recyclerview fixed that bug

implementation "androidx.recyclerview:recyclerview:1.1.0"