Android Studio Phase 31st-record Recyclerview scrolling position and restore

Source: Internet
Author: User

The code has been sorted out, see below ~ one day you will use the ~ welcome ha ~650) this.width=650; "src=" Http://img.baidu.com/hi/jx2/j_0057.gif "alt=" j_0057.gif "/ >

Monitor Recyclerview scrolling Status Mrecyclerview.addonscrolllistener (New recyclerview.onscrolllistener ()  {      @Override     public void onscrollstatechanged (recyclerview  recyclerview, int newstate)  {         Super.onscrollstatechanged (recyclerview, newstate);         if ( Recyclerview.getlayoutmanager ()  != null)  {             getpositionandoffset ();        }     });/** *  record Recyclerview current position  */private void getpositionandoffset ()  {     LinearLayoutManager layoutManager =  (Linearlayoutmanager)   Mrecyclerview.getlayoutmanager ();     //gets the first visual view    view  Topview = layoutmanager.getchildat (0); &nbsP;   if (topview != null)  {        // Gets the offset from the top of the View         lastoffset = topview.gettop ();         //gets the array position of the view          Lastposition = layoutmanager.getposition (TopView);    }}/** *  Let Recyclerview scroll to the specified position  */private void scrolltoposition ()  {    if ( Mrecyclerview.getlayoutmanager ()  != null && lastposition >= 0)  {          ((Linearlayoutmanager)  mrecyclerview.getlayoutmanager ()). Scrolltopositionwithoffset (lastposition, lastoffset);     }}

650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M01/8D/BC/wKiom1iofFPScKJEAAQ8zhtm9UY253.gif "title=" C2adb464tw1etn3dny1qng208c04p7bj.gif "alt=" Wkiom1ioffpsckjeaaq8zhtm9uy253.gif "/>

This article is from the "Liangxiao Technology Center" blog, please be sure to keep this source http://liangxiao.blog.51cto.com/3626612/1899155

Android Studio Phase 31st-record Recyclerview scrolling position and restore

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.