NestedScrollview won't start from top
Asked Answered
S

6

59

I have a Recyclerview in a NestedScrollview.. everything is working fine except one thig. I have total three view in NestedScrollview First two are LinearLayout then Recyclerview. when i run my app the Activity don't show top two layout it starts from top of the Recyclerview.

How its show my layout:

How its show my layout

How its suppose to show:

How its suppose to show

And i am loading this enite layout under a viewpager and my viewpager is a child of Coordinator Layout.

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView
android:id="@+id/scrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/home_layout_background">

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

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal">

        <com.daimajia.slider.library.SliderLayout
            android:id="@+id/image_slider"
            android:layout_width="match_parent"
            android:layout_height="@dimen/image_slider_height"
            android:layout_marginTop="@dimen/image_slider_top_margin" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="@dimen/popular_fragment_side_padding"
        android:layout_marginRight="@dimen/popular_fragment_side_padding"
        android:layout_marginTop="@dimen/popular_fragment_side_padding"
        android:orientation="horizontal"
        android:weightSum="4">

        <RelativeLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1">

            <RelativeLayout
                android:id="@+id/free_delivery"
                android:layout_width="76dp"
                android:layout_height="76dp"
                android:layout_centerInParent="true"
                android:background="@color/white">

                <RelativeLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerInParent="true">

                    <ImageView
                        android:id="@+id/btnImageViewFreeDelivery"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_centerHorizontal="true"
                        android:background="@drawable/icon_free_delivery" />

                    <TextView
                        android:id="@+id/btnTextFreeDelivery"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_below="@+id/btnImageViewFreeDelivery"
                        android:layout_centerHorizontal="true"
                        android:layout_marginTop="2dp"
                        android:text="@string/free_delivery_txt"
                        android:textColor="@color/popular_fragment_four_btn_txt"
                        android:textSize="@dimen/popular_fragment_four_btn_txt_size" />
                </RelativeLayout>

            </RelativeLayout>

        </RelativeLayout>

        <RelativeLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1">

            <RelativeLayout
                android:id="@+id/flash_deals"
                android:layout_width="76dp"
                android:layout_height="76dp"
                android:layout_centerInParent="true"
                android:background="@color/white">


                <RelativeLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerInParent="true">

                    <ImageView
                        android:id="@+id/btnImageViewFlashDeals"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_centerHorizontal="true"
                        android:background="@drawable/icon_flash_deals" />

                    <TextView
                        android:id="@+id/btnTextFlashDeals"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_below="@+id/btnImageViewFlashDeals"
                        android:layout_centerHorizontal="true"
                        android:layout_marginTop="2dp"
                        android:text="@string/flash_deals_txt"
                        android:textColor="@color/popular_fragment_four_btn_txt"
                        android:textSize="@dimen/popular_fragment_four_btn_txt_size" />
                </RelativeLayout>

            </RelativeLayout>

        </RelativeLayout>

        <RelativeLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1">

            <RelativeLayout
                android:id="@+id/for_you"
                android:layout_width="76dp"
                android:layout_height="76dp"
                android:layout_centerInParent="true"
                android:background="@color/white">

                <RelativeLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerInParent="true">

                    <ImageView
                        android:id="@+id/btnImageViewForYou"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_centerHorizontal="true"
                        android:background="@drawable/icon_for_you" />

                    <TextView
                        android:id="@+id/btnTextForYou"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_below="@+id/btnImageViewForYou"
                        android:layout_centerHorizontal="true"
                        android:layout_marginTop="2dp"
                        android:text="@string/for_you_txt"
                        android:textColor="@color/popular_fragment_four_btn_txt"
                        android:textSize="@dimen/popular_fragment_four_btn_txt_size" />
                </RelativeLayout>


            </RelativeLayout>
        </RelativeLayout>

        <RelativeLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1">

            <RelativeLayout
                android:id="@+id/shake_deals"
                android:layout_width="76dp"
                android:layout_height="76dp"
                android:layout_centerInParent="true"
                android:background="@color/white">

                <RelativeLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerInParent="true">

                    <ImageView
                        android:id="@+id/btnImageViewShakeDeals"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_centerHorizontal="true"
                        android:background="@drawable/icon_shake_deals" />

                    <TextView
                        android:id="@+id/btnTextShakeDeals"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_below="@+id/btnImageViewShakeDeals"
                        android:layout_centerHorizontal="true"
                        android:layout_marginTop="2dp"
                        android:text="@string/shake_deals"
                        android:textColor="@color/popular_fragment_four_btn_txt"
                        android:textSize="@dimen/popular_fragment_four_btn_txt_size" />
                </RelativeLayout>

            </RelativeLayout>
        </RelativeLayout>
    </LinearLayout>

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recycler_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginLeft="@dimen/popular_fragment_side_padding"
        android:layout_marginRight="@dimen/popular_fragment_side_padding"
        android:layout_marginTop="18dp"
        android:scrollbars="none" />

</LinearLayout>

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

My ViewPager Layout

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
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.v4.view.ViewPager
    android:id="@+id/viewPager"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/home_layout_background"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

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

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:layout_gravity="center"
        android:background="@drawable/toolbar_background"
        app:layout_scrollFlags="scroll|enterAlways">

        <TextView
            android:id="@+id/toolbar_title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:text="@string/title_home"
            android:textColor="@color/toolbar_title_txt_color"
            android:textSize="@dimen/toolbar_txt_size"
            android:textStyle="bold" />

    </android.support.v7.widget.Toolbar>


    <android.support.design.widget.TabLayout android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/white"
        app:tabMode="scrollable"
        app:tabTextColor="@color/tab_bar_txt"
        app:tabIndicatorColor="@color/tab_bar_txt_selected"
        app:tabSelectedTextColor="@color/tab_bar_txt_selected"
        app:tabTextAppearance="@style/TabTextAppeareance"/>

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



</android.support.design.widget.CoordinatorLayout>
Salesroom answered 7/11, 2015 at 15:2 Comment(0)
E
66

It is a problem about focus. Try :

findViewById(R.id.recycler_view).setFocusable(false);
findViewById(R.id.temp).requestFocus();

<?xml version="1.0" encoding="utf-8"?>
    <android.support.v4.widget.NestedScrollView
    android:id="@+id/scrollView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/home_layout_background">

    <LinearLayout
        android:id="@+id/temp"
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="horizontal">

            <com.daimajia.slider.library.SliderLayout
                android:id="@+id/image_slider"
                android:layout_width="match_parent"
                android:layout_height="@dimen/image_slider_height"
                android:layout_marginTop="@dimen/image_slider_top_margin" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="@dimen/popular_fragment_side_padding"
            android:layout_marginRight="@dimen/popular_fragment_side_padding"
            android:layout_marginTop="@dimen/popular_fragment_side_padding"
            android:orientation="horizontal"
            android:weightSum="4">

            <RelativeLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1">

                <RelativeLayout
                    android:id="@+id/free_delivery"
                    android:layout_width="76dp"
                    android:layout_height="76dp"
                    android:layout_centerInParent="true"
                    android:background="@color/white">

                    <RelativeLayout
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_centerInParent="true">

                        <ImageView
                            android:id="@+id/btnImageViewFreeDelivery"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_centerHorizontal="true"
                            android:background="@drawable/icon_free_delivery" />

                        <TextView
                            android:id="@+id/btnTextFreeDelivery"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_below="@+id/btnImageViewFreeDelivery"
                            android:layout_centerHorizontal="true"
                            android:layout_marginTop="2dp"
                            android:text="@string/free_delivery_txt"
                            android:textColor="@color/popular_fragment_four_btn_txt"
                            android:textSize="@dimen/popular_fragment_four_btn_txt_size" />
                    </RelativeLayout>

                </RelativeLayout>

            </RelativeLayout>

            <RelativeLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1">

                <RelativeLayout
                    android:id="@+id/flash_deals"
                    android:layout_width="76dp"
                    android:layout_height="76dp"
                    android:layout_centerInParent="true"
                    android:background="@color/white">


                    <RelativeLayout
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_centerInParent="true">

                        <ImageView
                            android:id="@+id/btnImageViewFlashDeals"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_centerHorizontal="true"
                            android:background="@drawable/icon_flash_deals" />

                        <TextView
                            android:id="@+id/btnTextFlashDeals"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_below="@+id/btnImageViewFlashDeals"
                            android:layout_centerHorizontal="true"
                            android:layout_marginTop="2dp"
                            android:text="@string/flash_deals_txt"
                            android:textColor="@color/popular_fragment_four_btn_txt"
                            android:textSize="@dimen/popular_fragment_four_btn_txt_size" />
                    </RelativeLayout>

                </RelativeLayout>

            </RelativeLayout>

            <RelativeLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1">

                <RelativeLayout
                    android:id="@+id/for_you"
                    android:layout_width="76dp"
                    android:layout_height="76dp"
                    android:layout_centerInParent="true"
                    android:background="@color/white">

                    <RelativeLayout
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_centerInParent="true">

                        <ImageView
                            android:id="@+id/btnImageViewForYou"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_centerHorizontal="true"
                            android:background="@drawable/icon_for_you" />

                        <TextView
                            android:id="@+id/btnTextForYou"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_below="@+id/btnImageViewForYou"
                            android:layout_centerHorizontal="true"
                            android:layout_marginTop="2dp"
                            android:text="@string/for_you_txt"
                            android:textColor="@color/popular_fragment_four_btn_txt"
                            android:textSize="@dimen/popular_fragment_four_btn_txt_size" />
                    </RelativeLayout>


                </RelativeLayout>
            </RelativeLayout>

            <RelativeLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1">

                <RelativeLayout
                    android:id="@+id/shake_deals"
                    android:layout_width="76dp"
                    android:layout_height="76dp"
                    android:layout_centerInParent="true"
                    android:background="@color/white">

                    <RelativeLayout
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_centerInParent="true">

                        <ImageView
                            android:id="@+id/btnImageViewShakeDeals"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_centerHorizontal="true"
                            android:background="@drawable/icon_shake_deals" />

                        <TextView
                            android:id="@+id/btnTextShakeDeals"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_below="@+id/btnImageViewShakeDeals"
                            android:layout_centerHorizontal="true"
                            android:layout_marginTop="2dp"
                            android:text="@string/shake_deals"
                            android:textColor="@color/popular_fragment_four_btn_txt"
                            android:textSize="@dimen/popular_fragment_four_btn_txt_size" />
                    </RelativeLayout>

                </RelativeLayout>
            </RelativeLayout>
        </LinearLayout>

        <android.support.v7.widget.RecyclerView
            android:id="@+id/recycler_view"
            android:focusable="false"
            android:focusableInTouchMode="false"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginLeft="@dimen/popular_fragment_side_padding"
            android:layout_marginRight="@dimen/popular_fragment_side_padding"
            android:layout_marginTop="18dp"
            android:scrollbars="none" />

    </LinearLayout>

    </android.support.v4.widget.NestedScrollView>
Elkin answered 7/11, 2015 at 15:22 Comment(3)
yes. he is right. just add mRecyclerView.setFoucsable(false);. and the reason is hereStrand
thanks for this. took a long time searching. I have a similar layout, with a viewpager and a drawerlayout. the strange scroll issue hapenned when I opened the navigationdrawer. now it's all fixed :)Scleritis
thanks a lot, it works for me ! i am using daimajia slider and it was causing the recycler view to keep scrolling.Mishear
B
120

I had the same problem, and I fixed it the following way.

Add android:descendantFocusability="blocksDescendants" to the Linear Layout which is the only child of the Nested Scroll View.

This allows the Nested Scroll View to start from the top with minimal change to code.

Beira answered 4/7, 2017 at 6:28 Comment(5)
This should be the accepted answer, because doesn't change the style of views. while android:focusableInTouchMode="true" make view look like if it is clicked.Coherent
but doesn't it block child views from getting focused? This would make the app completely not accessible!Surfeit
Should be accepted answer, nothing from above worked. Just a single line did. ExcellentAbjure
Thanks a ton for this solution. Had a similar issue, however it only occurs on versions <=8.1. I have a fragment that basically has a NestedScrollView (with a LinearLayout as child) inside a CoordinatorLayout that sets app:layout_behavior="@string/bottom_sheet_behavior". Sometimes, for instance when the host activity of the fragment was paused and resumed later on, the NestedScrollView did not scroll to the top layout of its child (i.e. LinearLayout), but was strangely offset. Setting android:descendantFocusability="blocksDescendants" to the LinearLayoutsolved my problem :)Bushweller
This works, but it causes all child views to be unaccessable. EditTexts cant be selected anymore.Emmanuel
E
66

It is a problem about focus. Try :

findViewById(R.id.recycler_view).setFocusable(false);
findViewById(R.id.temp).requestFocus();

<?xml version="1.0" encoding="utf-8"?>
    <android.support.v4.widget.NestedScrollView
    android:id="@+id/scrollView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/home_layout_background">

    <LinearLayout
        android:id="@+id/temp"
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="horizontal">

            <com.daimajia.slider.library.SliderLayout
                android:id="@+id/image_slider"
                android:layout_width="match_parent"
                android:layout_height="@dimen/image_slider_height"
                android:layout_marginTop="@dimen/image_slider_top_margin" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="@dimen/popular_fragment_side_padding"
            android:layout_marginRight="@dimen/popular_fragment_side_padding"
            android:layout_marginTop="@dimen/popular_fragment_side_padding"
            android:orientation="horizontal"
            android:weightSum="4">

            <RelativeLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1">

                <RelativeLayout
                    android:id="@+id/free_delivery"
                    android:layout_width="76dp"
                    android:layout_height="76dp"
                    android:layout_centerInParent="true"
                    android:background="@color/white">

                    <RelativeLayout
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_centerInParent="true">

                        <ImageView
                            android:id="@+id/btnImageViewFreeDelivery"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_centerHorizontal="true"
                            android:background="@drawable/icon_free_delivery" />

                        <TextView
                            android:id="@+id/btnTextFreeDelivery"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_below="@+id/btnImageViewFreeDelivery"
                            android:layout_centerHorizontal="true"
                            android:layout_marginTop="2dp"
                            android:text="@string/free_delivery_txt"
                            android:textColor="@color/popular_fragment_four_btn_txt"
                            android:textSize="@dimen/popular_fragment_four_btn_txt_size" />
                    </RelativeLayout>

                </RelativeLayout>

            </RelativeLayout>

            <RelativeLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1">

                <RelativeLayout
                    android:id="@+id/flash_deals"
                    android:layout_width="76dp"
                    android:layout_height="76dp"
                    android:layout_centerInParent="true"
                    android:background="@color/white">


                    <RelativeLayout
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_centerInParent="true">

                        <ImageView
                            android:id="@+id/btnImageViewFlashDeals"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_centerHorizontal="true"
                            android:background="@drawable/icon_flash_deals" />

                        <TextView
                            android:id="@+id/btnTextFlashDeals"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_below="@+id/btnImageViewFlashDeals"
                            android:layout_centerHorizontal="true"
                            android:layout_marginTop="2dp"
                            android:text="@string/flash_deals_txt"
                            android:textColor="@color/popular_fragment_four_btn_txt"
                            android:textSize="@dimen/popular_fragment_four_btn_txt_size" />
                    </RelativeLayout>

                </RelativeLayout>

            </RelativeLayout>

            <RelativeLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1">

                <RelativeLayout
                    android:id="@+id/for_you"
                    android:layout_width="76dp"
                    android:layout_height="76dp"
                    android:layout_centerInParent="true"
                    android:background="@color/white">

                    <RelativeLayout
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_centerInParent="true">

                        <ImageView
                            android:id="@+id/btnImageViewForYou"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_centerHorizontal="true"
                            android:background="@drawable/icon_for_you" />

                        <TextView
                            android:id="@+id/btnTextForYou"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_below="@+id/btnImageViewForYou"
                            android:layout_centerHorizontal="true"
                            android:layout_marginTop="2dp"
                            android:text="@string/for_you_txt"
                            android:textColor="@color/popular_fragment_four_btn_txt"
                            android:textSize="@dimen/popular_fragment_four_btn_txt_size" />
                    </RelativeLayout>


                </RelativeLayout>
            </RelativeLayout>

            <RelativeLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1">

                <RelativeLayout
                    android:id="@+id/shake_deals"
                    android:layout_width="76dp"
                    android:layout_height="76dp"
                    android:layout_centerInParent="true"
                    android:background="@color/white">

                    <RelativeLayout
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_centerInParent="true">

                        <ImageView
                            android:id="@+id/btnImageViewShakeDeals"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_centerHorizontal="true"
                            android:background="@drawable/icon_shake_deals" />

                        <TextView
                            android:id="@+id/btnTextShakeDeals"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_below="@+id/btnImageViewShakeDeals"
                            android:layout_centerHorizontal="true"
                            android:layout_marginTop="2dp"
                            android:text="@string/shake_deals"
                            android:textColor="@color/popular_fragment_four_btn_txt"
                            android:textSize="@dimen/popular_fragment_four_btn_txt_size" />
                    </RelativeLayout>

                </RelativeLayout>
            </RelativeLayout>
        </LinearLayout>

        <android.support.v7.widget.RecyclerView
            android:id="@+id/recycler_view"
            android:focusable="false"
            android:focusableInTouchMode="false"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginLeft="@dimen/popular_fragment_side_padding"
            android:layout_marginRight="@dimen/popular_fragment_side_padding"
            android:layout_marginTop="18dp"
            android:scrollbars="none" />

    </LinearLayout>

    </android.support.v4.widget.NestedScrollView>
Elkin answered 7/11, 2015 at 15:22 Comment(3)
yes. he is right. just add mRecyclerView.setFoucsable(false);. and the reason is hereStrand
thanks for this. took a long time searching. I have a similar layout, with a viewpager and a drawerlayout. the strange scroll issue hapenned when I opened the navigationdrawer. now it's all fixed :)Scleritis
thanks a lot, it works for me ! i am using daimajia slider and it was causing the recycler view to keep scrolling.Mishear
W
14

Just add this line to child of NestedScrollView in xml:

android:focusableInTouchMode="true"
Warison answered 9/8, 2017 at 11:18 Comment(1)
I put a Linear layout inside a NestedScrollView and put every view inside that Linear layout which is a child of parent, NestedScrollView and added android:focusableInTouchMode= "true" in first child of NestedScrollView and it works in my case.Overbite
M
2
<android.support.v4.widget.NestedScrollView
            android:id="@+id/nested_scrool_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:descendantFocusability="beforeDescendants"
            android:focusableInTouchMode="true"
            android:fitsSystemWindows="false"
            >

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


NestedScrollView nested_scrool_view;
nested_scrool_view = mView.findViewById(R.id.nested_scrool_view);
nested_scrool_view.smoothScrollTo(0,0); //set it on top
More answered 28/6, 2019 at 13:50 Comment(1)
It's been a while but my solution was "smoothScrollTo(0,0)". It worked like a charm. Thanks!Pitch
I
0

I have several EditTexts and a RecyclerView in a NestedScrollView, So I added this code to my RecyclerView android:descendantFocusability="blocksDescendants"

and now when the screen is opened, the NestedScroll position is always at the top."

Immensurable answered 20/3 at 10:54 Comment(0)
R
-1

Add this line in NestedScrollView 's child Layout

android:descendantFocusability="afterDescendants"
Repro answered 7/12, 2017 at 20:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.