Recyclerview Changing Items During Scroll

前端 未结 15 707
我在风中等你
我在风中等你 2020-11-27 10:38

I have a RecyclerView. Each row has a play button, textview and Progressbar. when click on the play button have to play audio from my sdcard and have to progress Progressbar

相关标签:
15条回答
  • 2020-11-27 11:25

    When we are changing RecyclerView items dynamically (i.e. when changing background color of a specific RecyclerView item), it could change appearance of the items in unexpected ways when scrolling due to the nature of how RecyclerView reuse its items.

    However to avoid that it is possible to use android.support.v4.widget.NestedScrollView wrapped around the RecyclerView and letting the NestedScrollView handle the scrolling.

    <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">
    
            <android.support.v7.widget.RecyclerView
                android:id="@+id/recycler_view"
                android:layout_width="match_parent"
                android:layout_height="match_parent"/>
    
       </LinearLayout>
    </android.support.v4.widget.NestedScrollView>
    

    And then in the code you can disable nested scrolling for the RecyclerView to smooth out scrolling by letting only the NestedScrollView to handle scrolling.

    ViewCompat.setNestedScrollingEnabled(recyclerView, false);
    
    0 讨论(0)
  • 2020-11-27 11:26

    This line changes progress to 0 on each bind

    myViewHolder.progressplay.setProgress(0);
    

    Save its state somewhere then load it in this same line.

    0 讨论(0)
  • 2020-11-27 11:27

    Why don't you try like this,

        HashMap<String, Integer> progressHashMap = new HashMap<>();
    
        //...
        if(!progressHashMap.containsKey(downloadpath)){
            progressHashMap.put(downloadpath, mPlayer.getCurrentPosition());
        }
    
        progressbar.setProgress(progressHashMap.get(downloadpath));
    
    0 讨论(0)
提交回复
热议问题