Issue
This is my first post here on StackOverflow. I have an issue with the horizontal androidx.recyclerview.widget.RecyclerView
: the scrolling effect is really buggy. I'm using a custom adapter, but I don't think that's the issue. I'm also using Picasso for the images.
- RecyclerView:
<androidx.recyclerview.widget.RecyclerView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/test2"
android:paddingTop="10dp"
android:nestedScrollingEnabled="false"
android:clipToPadding="false"
android:clipChildren="false"
android:overScrollMode="never"
tools:ignore="MissingConstraints"/>
- MainFilmsListAdapter.java (my adapter):
public class MainFilmsListAdapter extends RecyclerView.Adapter<MainFilmsListAdapter.MyViewHolder> {
private List<MainFilms> filmsList;
class MyViewHolder extends RecyclerView.ViewHolder {
TextView mainFilmsTitle, mainFilmsURL;
ImageView mainFilmsImage;
MyViewHolder(View view) {
super(view);
mainFilmsTitle = view.findViewById(R.id.main_films_item_title);
mainFilmsURL = view.findViewById(R.id.main_films_item_url);
mainFilmsImage = view.findViewById(R.id.main_films_item_image);
}
}
public MainFilmsListAdapter(List<MainFilms> filmsList) {
this.filmsList = filmsList;
}
@NonNull
@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.main_films_item, parent, false);
return new MyViewHolder(itemView);
}
@Override
public void onBindViewHolder(MyViewHolder holder, int position) {
MainFilms film = filmsList.get(position);
holder.mainFilmsTitle.setText(film.getMainFilmsTitle());
holder.mainFilmsURL.setText(film.getMainFilmsURL());
Picasso.get()
.load(filmsList.get(position).getMainFilmsImage())
.fit()
.centerCrop()
.into(holder.mainFilmsImage);
}
@Override
public int getItemCount() {
return filmsList.size();
}
}
- MainFilms.java:
public class MainFilms {
String mainFilmsTitle;
String mainFilmsImage;
String mainFilmsURL;
public MainFilms(String mainFilmsTitle, String mainFilmsURL, String mainFilmsImage) {
this.mainFilmsTitle = mainFilmsTitle;
this.mainFilmsURL = mainFilmsURL;
this.mainFilmsImage = mainFilmsImage;
}
public String getMainFilmsTitle() {
return mainFilmsTitle;
}
public String getMainFilmsURL() {
return mainFilmsURL;
}
public String getMainFilmsImage() {
return mainFilmsImage;
}
}
- MainActivity.java (RecyclerView):
mAdapter = new MainFilmsListAdapter(filmsList);
LinearLayoutManager mLayoutManager = new LinearLayoutManager(getApplicationContext(), LinearLayoutManager.HORIZONTAL, false);
recyclerView.setLayoutManager(mLayoutManager);
recyclerView.setItemAnimator(new DefaultItemAnimator());
recyclerView.setAdapter(mAdapter);
- Result: https://i.imgur.com/64CPQDY.mp4 (I can't upload because of the file size, and sorry for the bad quality, but my PC is slow)
I can't figure out where the problem is, I've been looking for a solution for more than 5 hours. All I notice is that the view freezes when it reaches a certain item in the RecyclerView. I also tested the app on my Android cellphone. The number of itmes in the RecyclerView is constant.
Solution
Looks like a problem with images loading.
You can try to read this related question and answers - Recyclerview painfully slow to load cached images form Picasso
Answered By - Eugene Kuzmenko
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.