There was a problem using CardView. When scrolling the list, there is an overlay of old data, i.e. the list seems to be displayed in the background, see the video link. Below is the code that I used. Tell me which way to look to solve this problem.
Video : https://www.dropbox.com/s/7p8pihs6aqxkovb/device-2016-07-14-151103.mp4?dl=0
Fragment code in which everything is displayed:
public class PreviewFragment extends Fragment { private List<Person> persons; private RecyclerView rv; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.recyclerview_activity, null); rv=(RecyclerView)v.findViewById(R.id.rv); LinearLayoutManager llm = new LinearLayoutManager(getActivity()); rv.setLayoutManager(llm); initializeData(); initializeAdapter(); return v; } private void initializeData(){ persons = new ArrayList<>(); for(int i=0; i<50; i++){ persons.add(new Person("Name_" + i, "years old " + i*i, android.R.drawable.arrow_up_float)); } } private void initializeAdapter(){ RVAdapter adapter = new RVAdapter(persons); rv.setAdapter(adapter); } }
Layout for Fragment
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingTop="60dp"> <android.support.v7.widget.RecyclerView android:id="@+id/rv" android:layout_width="match_parent" android:layout_height="wrap_content"> </android.support.v7.widget.RecyclerView>
Layout list item
<ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/person_photo" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:layout_marginRight="16dp"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/person_name" android:layout_toRightOf="@+id/person_photo" android:layout_alignParentTop="true" android:textSize="30sp"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/person_age" android:layout_toRightOf="@+id/person_photo" android:layout_below="@+id/person_name"/> </RelativeLayout>
Activity
? - Vladyslav Matviienkoreplace()
method is used andadd()
directly adds. - Silento