Sushant Gosavi
Sushant Gosavi

Reputation: 3845

Allow only One view that has ablility to scroll the CoordinatorLayout . eg.like Handle view work in Sliding panel

I have search a lot but not found same question on stack-overflow

Problem - I just want that only one view that scroll CoordinatorLayout similar like handle view work in Sliding Panel layout

but in my current layout i have two views one is handle view (Textview with text "Route Plan") and other is RecyclerView What I want is when user click and drag on handle view CoordinatorLayout should scroll but when user click on RecyclerView it should not scroll CoordinatorLayout it shoud scroll only RecyclerView items is it possible

here is my current layout -

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/bg_sub_tab"
    android:padding="5pt"
    tools:ignore="RtlHardcoded">
    ​

    <android.support.design.widget.AppBarLayout
        android:id="@+id/materialup.appbar"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginBottom="50dp"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
        ​

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/main.collapsing"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:contentScrim="?colorPrimary"
            app:expandedTitleMarginBottom="94dp"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">

            <FrameLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_above="@+id/tvRoutePlan"
                android:layout_alignParentTop="true"
                android:gravity="top">

                <RelativeLayout
                    android:id="@+id/mapContainer"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent" />
            </FrameLayout>


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


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <android.support.v4.widget.NestedScrollView
                android:id="@+id/content"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:scrollbars="none"
                app:layout_behavior="@string/appbar_scrolling_view_behavior"><!--com.indus.corelib.ui.FixedScrollingViewBehavior -->

                <TextView
                    android:id="@+id/tvRoutePlan"
                    android:layout_width="match_parent"
                    android:layout_height="50dp"
                    android:layout_alignParentBottom="true"
                    android:background="@drawable/map_list_title_gradient"
                    android:drawSelectorOnTop="true"
                    android:gravity="center_horizontal|center_vertical"
                    android:padding="5pt"
                    android:text="Route Plan"
                    android:textColor="@android:color/white"
                    android:textSize="25sp"
                    android:visibility="visible"
                    app:layout_behavior="@string/appbar_scrolling_view_behavior" />
            </android.support.v4.widget.NestedScrollView>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">

                <android.support.v7.widget.RecyclerView
                    android:id="@android:id/list"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:clipToPadding="true"
                    android:nestedScrollingEnabled="false"
                    android:background="@android:color/transparent"
                    android:cacheColorHint="@android:color/white"
                    android:descendantFocusability="blocksDescendants"
                    android:divider="@android:color/darker_gray"
                    android:dividerHeight="@dimen/divider_height"
                    android:drawSelectorOnTop="true"
                    android:smoothScrollbar="true" />
            </LinearLayout>


        </LinearLayout>
    </LinearLayout>


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

Note :- when i used other view insted of RecyclerView than it work perfectly as i want like when i click and drag that view CoordinatorLayout not move but i need recycler view there to show list :(

Upvotes: 0

Views: 171

Answers (2)

Sushant Gosavi
Sushant Gosavi

Reputation: 3845

Yup , I got the answer by myself

Just stop scroll of RecyclerView and it just work what i want

                 <android.support.v7.widget.RecyclerView
                        android:id="@android:id/list"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:background="@android:color/transparent"
                        android:cacheColorHint="@android:color/white"
                        android:descendantFocusability="blocksDescendants"
                        android:divider="@android:color/darker_gray"
                        android:dividerHeight="@dimen/divider_height"
                        android:drawSelectorOnTop="true"
                        android:nestedScrollingEnabled="false"
                        android:overScrollMode="never"
                        android:fadeScrollbars="false"/> 

also i used in java file

        mListView = (RecyclerView) rootView.findViewById(android.R.id.list);
        mListView.setNestedScrollingEnabled(false);
        mListView.setOverScrollMode(ListView.OVER_SCROLL_NEVER);
        mListView.stopScroll();

mListView.stopScroll() This is real game changer But i am not happy that no one try to solve my prob except Bruno Ferreira :( Thanks Bruno for help

Upvotes: 0

Bruno Ferreira
Bruno Ferreira

Reputation: 1571

So try do something like this:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/bg_sub_tab"
    android:padding="5pt"
    tools:ignore="RtlHardcoded">
    ​

    <android.support.design.widget.AppBarLayout
        android:id="@+id/materialup.appbar"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginBottom="50dp"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
        ​

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/main.collapsing"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:contentScrim="?colorPrimary"
            app:expandedTitleMarginBottom="94dp"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">

            <FrameLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_above="@+id/tvRoutePlan"
                android:layout_alignParentTop="true"
                android:gravity="top">

                <RelativeLayout
                    android:id="@+id/mapContainer"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent" />
            </FrameLayout>


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


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <android.support.v4.widget.NestedScrollView
                android:id="@+id/content"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:scrollbars="none"
                app:layout_behavior="@string/appbar_scrolling_view_behavior"><!--com.indus.corelib.ui.FixedScrollingViewBehavior -->

                <TextView
                    android:id="@+id/tvRoutePlan"
                    android:layout_width="match_parent"
                    android:layout_height="50dp"
                    android:layout_alignParentBottom="true"
                    android:background="@drawable/map_list_title_gradient"
                    android:drawSelectorOnTop="true"
                    android:gravity="center_horizontal|center_vertical"
                    android:padding="5pt"
                    android:text="Route Plan"
                    android:textColor="@android:color/white"
                    android:textSize="25sp"
                    android:visibility="visible"
                    app:layout_behavior="@string/appbar_scrolling_view_behavior" />
            </android.support.v4.widget.NestedScrollView>    

        </LinearLayout>
    </LinearLayout>

                <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">

                <android.support.v7.widget.RecyclerView
                    android:id="@android:id/list"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:clipToPadding="true"
                    android:nestedScrollingEnabled="false"
                    android:background="@android:color/transparent"
                    android:cacheColorHint="@android:color/white"
                    android:descendantFocusability="blocksDescendants"
                    android:divider="@android:color/darker_gray"
                    android:dividerHeight="@dimen/divider_height"
                    android:drawSelectorOnTop="true"
                    android:smoothScrollbar="true" />
            </LinearLayout>


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

So remove recycleview from your layout behavior parent. Because the recycleview isnt inside the layout behavior parent he dont do the scroll flag. If this not Works the oter way is put the CoordinatorLayout inside other layout like a LinearLayout and recycleview outside CoordinatorLayout but inside LinearLayout.

Note: It's my idea i don't know if it Works.

Upvotes: 1

Related Questions