Scroll NestedScrollView to top when rotating device





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















I have following layout includes a NestedScrollView(it has a RecyclerView inside) :



<android.support.constraint.motion.MotionLayout
android:id="@+id/details_motion"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layoutDescription="@xml/scene_show_details">

<ImageView
android:id="@+id/details_backdrop"
android:layout_width="0dp"
android:layout_height="0dp"
android:scaleType="centerCrop"
app:imageUrl="@{movie.backdropPath}"
tools:ignore="ContentDescription" />

<android.support.v7.widget.AppCompatImageView
android:id="@+id/details_poster"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="@drawable/placeholder"
android:scaleType="centerCrop"
android:transformPivotX="0px"
android:transformPivotY="0px"
android:transitionName="@string/view_name_header_image"
app:imageUrl="@{movie.posterPath}" />

<android.support.v7.widget.Toolbar
android:id="@+id/details_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
app:theme="@style/Toolbar" />

<android.support.v4.widget.NestedScrollView
android:id="@+id/details_rv"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="@color/window_background"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/details_appbar_background">

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

<TextView
style="@style/TmdbMargin.Small"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/padding_normal"
android:text="@{@string/release_date(movie.releaseDate)}" />

<TextView
style="@style/TmdbMargin.Small"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@{@string/rating(movie.voteAverage)}" />

<TextView
style="@style/TmdbMargin.Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/summary" />

<TextView
android:id="@+id/summary"
style="@style/TmdbMargin.Body"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@{movie.overview}" />

<include
layout="@layout/trailers"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/padding_normal"
android:layout_marginTop="@dimen/padding_large"
app:vm="@{vm}"
tools:ignore="RtlHardcoded" />

<TextView
style="@style/TmdbMargin.Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/padding_normal"
android:text="@string/cast"
app:visibleGone="@{vm.isCastVisible}" />

<android.support.v7.widget.RecyclerView
android:id="@+id/cast_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="12dp" />

</LinearLayout>

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

</android.support.constraint.motion.MotionLayout>


When I rotate the device (for instance when I am in the middle of RecyclerView list), I want to scroll to top of NestedScrollView. I tried :



nestedScrollView.fullScroll(View.FOCUS_UP);
nestedScrollView.scrollTo(0,0);


But none of them worked in my case. Could be any solution for me?



Source code can be found at : https://github.com/Ali-Rezaei/TMDb-Paging










share|improve this question

























  • Could give me your api key?

    – Dmitro Ivanov
    Jan 3 at 17:08


















0















I have following layout includes a NestedScrollView(it has a RecyclerView inside) :



<android.support.constraint.motion.MotionLayout
android:id="@+id/details_motion"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layoutDescription="@xml/scene_show_details">

<ImageView
android:id="@+id/details_backdrop"
android:layout_width="0dp"
android:layout_height="0dp"
android:scaleType="centerCrop"
app:imageUrl="@{movie.backdropPath}"
tools:ignore="ContentDescription" />

<android.support.v7.widget.AppCompatImageView
android:id="@+id/details_poster"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="@drawable/placeholder"
android:scaleType="centerCrop"
android:transformPivotX="0px"
android:transformPivotY="0px"
android:transitionName="@string/view_name_header_image"
app:imageUrl="@{movie.posterPath}" />

<android.support.v7.widget.Toolbar
android:id="@+id/details_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
app:theme="@style/Toolbar" />

<android.support.v4.widget.NestedScrollView
android:id="@+id/details_rv"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="@color/window_background"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/details_appbar_background">

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

<TextView
style="@style/TmdbMargin.Small"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/padding_normal"
android:text="@{@string/release_date(movie.releaseDate)}" />

<TextView
style="@style/TmdbMargin.Small"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@{@string/rating(movie.voteAverage)}" />

<TextView
style="@style/TmdbMargin.Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/summary" />

<TextView
android:id="@+id/summary"
style="@style/TmdbMargin.Body"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@{movie.overview}" />

<include
layout="@layout/trailers"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/padding_normal"
android:layout_marginTop="@dimen/padding_large"
app:vm="@{vm}"
tools:ignore="RtlHardcoded" />

<TextView
style="@style/TmdbMargin.Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/padding_normal"
android:text="@string/cast"
app:visibleGone="@{vm.isCastVisible}" />

<android.support.v7.widget.RecyclerView
android:id="@+id/cast_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="12dp" />

</LinearLayout>

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

</android.support.constraint.motion.MotionLayout>


When I rotate the device (for instance when I am in the middle of RecyclerView list), I want to scroll to top of NestedScrollView. I tried :



nestedScrollView.fullScroll(View.FOCUS_UP);
nestedScrollView.scrollTo(0,0);


But none of them worked in my case. Could be any solution for me?



Source code can be found at : https://github.com/Ali-Rezaei/TMDb-Paging










share|improve this question

























  • Could give me your api key?

    – Dmitro Ivanov
    Jan 3 at 17:08














0












0








0








I have following layout includes a NestedScrollView(it has a RecyclerView inside) :



<android.support.constraint.motion.MotionLayout
android:id="@+id/details_motion"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layoutDescription="@xml/scene_show_details">

<ImageView
android:id="@+id/details_backdrop"
android:layout_width="0dp"
android:layout_height="0dp"
android:scaleType="centerCrop"
app:imageUrl="@{movie.backdropPath}"
tools:ignore="ContentDescription" />

<android.support.v7.widget.AppCompatImageView
android:id="@+id/details_poster"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="@drawable/placeholder"
android:scaleType="centerCrop"
android:transformPivotX="0px"
android:transformPivotY="0px"
android:transitionName="@string/view_name_header_image"
app:imageUrl="@{movie.posterPath}" />

<android.support.v7.widget.Toolbar
android:id="@+id/details_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
app:theme="@style/Toolbar" />

<android.support.v4.widget.NestedScrollView
android:id="@+id/details_rv"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="@color/window_background"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/details_appbar_background">

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

<TextView
style="@style/TmdbMargin.Small"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/padding_normal"
android:text="@{@string/release_date(movie.releaseDate)}" />

<TextView
style="@style/TmdbMargin.Small"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@{@string/rating(movie.voteAverage)}" />

<TextView
style="@style/TmdbMargin.Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/summary" />

<TextView
android:id="@+id/summary"
style="@style/TmdbMargin.Body"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@{movie.overview}" />

<include
layout="@layout/trailers"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/padding_normal"
android:layout_marginTop="@dimen/padding_large"
app:vm="@{vm}"
tools:ignore="RtlHardcoded" />

<TextView
style="@style/TmdbMargin.Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/padding_normal"
android:text="@string/cast"
app:visibleGone="@{vm.isCastVisible}" />

<android.support.v7.widget.RecyclerView
android:id="@+id/cast_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="12dp" />

</LinearLayout>

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

</android.support.constraint.motion.MotionLayout>


When I rotate the device (for instance when I am in the middle of RecyclerView list), I want to scroll to top of NestedScrollView. I tried :



nestedScrollView.fullScroll(View.FOCUS_UP);
nestedScrollView.scrollTo(0,0);


But none of them worked in my case. Could be any solution for me?



Source code can be found at : https://github.com/Ali-Rezaei/TMDb-Paging










share|improve this question
















I have following layout includes a NestedScrollView(it has a RecyclerView inside) :



<android.support.constraint.motion.MotionLayout
android:id="@+id/details_motion"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layoutDescription="@xml/scene_show_details">

<ImageView
android:id="@+id/details_backdrop"
android:layout_width="0dp"
android:layout_height="0dp"
android:scaleType="centerCrop"
app:imageUrl="@{movie.backdropPath}"
tools:ignore="ContentDescription" />

<android.support.v7.widget.AppCompatImageView
android:id="@+id/details_poster"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="@drawable/placeholder"
android:scaleType="centerCrop"
android:transformPivotX="0px"
android:transformPivotY="0px"
android:transitionName="@string/view_name_header_image"
app:imageUrl="@{movie.posterPath}" />

<android.support.v7.widget.Toolbar
android:id="@+id/details_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
app:theme="@style/Toolbar" />

<android.support.v4.widget.NestedScrollView
android:id="@+id/details_rv"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="@color/window_background"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/details_appbar_background">

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

<TextView
style="@style/TmdbMargin.Small"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/padding_normal"
android:text="@{@string/release_date(movie.releaseDate)}" />

<TextView
style="@style/TmdbMargin.Small"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@{@string/rating(movie.voteAverage)}" />

<TextView
style="@style/TmdbMargin.Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/summary" />

<TextView
android:id="@+id/summary"
style="@style/TmdbMargin.Body"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@{movie.overview}" />

<include
layout="@layout/trailers"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/padding_normal"
android:layout_marginTop="@dimen/padding_large"
app:vm="@{vm}"
tools:ignore="RtlHardcoded" />

<TextView
style="@style/TmdbMargin.Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/padding_normal"
android:text="@string/cast"
app:visibleGone="@{vm.isCastVisible}" />

<android.support.v7.widget.RecyclerView
android:id="@+id/cast_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="12dp" />

</LinearLayout>

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

</android.support.constraint.motion.MotionLayout>


When I rotate the device (for instance when I am in the middle of RecyclerView list), I want to scroll to top of NestedScrollView. I tried :



nestedScrollView.fullScroll(View.FOCUS_UP);
nestedScrollView.scrollTo(0,0);


But none of them worked in my case. Could be any solution for me?



Source code can be found at : https://github.com/Ali-Rezaei/TMDb-Paging







android android-recyclerview android-nestedscrollview






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 3 at 18:13









DemiDust

13911




13911










asked Jan 3 at 16:58









AliAli

4,7001651118




4,7001651118













  • Could give me your api key?

    – Dmitro Ivanov
    Jan 3 at 17:08



















  • Could give me your api key?

    – Dmitro Ivanov
    Jan 3 at 17:08

















Could give me your api key?

– Dmitro Ivanov
Jan 3 at 17:08





Could give me your api key?

– Dmitro Ivanov
Jan 3 at 17:08












1 Answer
1






active

oldest

votes


















0














I downloaded your app, problem is a while you trying to set scrollTo(0,0) or through fullScroll(View.FOCUS_UP), your list has not been initialized / rendered, list is empty when you calling operation scroll to top. Easy workaround is delayed your scroll operation (not so perfect way):



override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
// Your code ....
// ....
nestedScrollView = view.findViewById<NestedScrollView>(R.id.details_rv)
nestedScrollView.postDelayed({
nestedScrollView.scrollTo(0, 0)
}, 100)
}


While searched solution found a lot of great animations. You are MotionLayout monster :)






share|improve this answer
























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54026619%2fscroll-nestedscrollview-to-top-when-rotating-device%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    I downloaded your app, problem is a while you trying to set scrollTo(0,0) or through fullScroll(View.FOCUS_UP), your list has not been initialized / rendered, list is empty when you calling operation scroll to top. Easy workaround is delayed your scroll operation (not so perfect way):



    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
    super.onViewCreated(view, savedInstanceState)
    // Your code ....
    // ....
    nestedScrollView = view.findViewById<NestedScrollView>(R.id.details_rv)
    nestedScrollView.postDelayed({
    nestedScrollView.scrollTo(0, 0)
    }, 100)
    }


    While searched solution found a lot of great animations. You are MotionLayout monster :)






    share|improve this answer




























      0














      I downloaded your app, problem is a while you trying to set scrollTo(0,0) or through fullScroll(View.FOCUS_UP), your list has not been initialized / rendered, list is empty when you calling operation scroll to top. Easy workaround is delayed your scroll operation (not so perfect way):



      override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
      super.onViewCreated(view, savedInstanceState)
      // Your code ....
      // ....
      nestedScrollView = view.findViewById<NestedScrollView>(R.id.details_rv)
      nestedScrollView.postDelayed({
      nestedScrollView.scrollTo(0, 0)
      }, 100)
      }


      While searched solution found a lot of great animations. You are MotionLayout monster :)






      share|improve this answer


























        0












        0








        0







        I downloaded your app, problem is a while you trying to set scrollTo(0,0) or through fullScroll(View.FOCUS_UP), your list has not been initialized / rendered, list is empty when you calling operation scroll to top. Easy workaround is delayed your scroll operation (not so perfect way):



        override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        // Your code ....
        // ....
        nestedScrollView = view.findViewById<NestedScrollView>(R.id.details_rv)
        nestedScrollView.postDelayed({
        nestedScrollView.scrollTo(0, 0)
        }, 100)
        }


        While searched solution found a lot of great animations. You are MotionLayout monster :)






        share|improve this answer













        I downloaded your app, problem is a while you trying to set scrollTo(0,0) or through fullScroll(View.FOCUS_UP), your list has not been initialized / rendered, list is empty when you calling operation scroll to top. Easy workaround is delayed your scroll operation (not so perfect way):



        override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        // Your code ....
        // ....
        nestedScrollView = view.findViewById<NestedScrollView>(R.id.details_rv)
        nestedScrollView.postDelayed({
        nestedScrollView.scrollTo(0, 0)
        }, 100)
        }


        While searched solution found a lot of great animations. You are MotionLayout monster :)







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 3 at 17:57









        Dmitro IvanovDmitro Ivanov

        763149




        763149
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54026619%2fscroll-nestedscrollview-to-top-when-rotating-device%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            'app-layout' is not a known element: how to share Component with different Modules

            android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

            WPF add header to Image with URL pettitions [duplicate]