Если делаю с обычным recyclerview, то все отображается правильно, а если использую библиотеку
CarouselLayoutManager то на экране ничего.
Код активити
private List<String> keyList = new ArrayList<>();
private List<Winner> result_winners = new ArrayList<>();
winner_adapter = new WinnerAdapter(result_winners);
CarouselLayoutManager layoutManager = new CarouselLayoutManager(CarouselLayoutManager.HORIZONTAL, true);
layoutManager.setPostLayoutListener(new CarouselZoomPostLayoutListener());
layoutManager.setMaxVisibleItems(2);
winners_recycler = findViewById(R.id.winners_recycler);
winners_recycler.setLayoutManager(layoutManager);
winners_recycler.setHasFixedSize(true);
winners_recycler.setAdapter(winner_adapter);
winners_recycler.addOnScrollListener(new CenterScrollListener());
private void updateList() {
database.getReference("winners").addChildEventListener(new ChildEventListener() {
public void onChildAdded(@NonNull DataSnapshot dataSnapshot, @Nullable String s) {
result_winners.add(dataSnapshot.getValue(Winner.class));
winner_adapter.notifyDataSetChanged();
keyList.add(dataSnapshot.getKey());
}
public void onChildChanged(@NonNull DataSnapshot dataSnapshot, @Nullable String s) {
}
public void onChildRemoved(@NonNull DataSnapshot dataSnapshot) {
int index = keyList.indexOf(dataSnapshot.getKey());
result_winners.remove(index);
keyList.remove(index);
winner_adapter.notifyDataSetChanged();
}
public void onChildMoved(@NonNull DataSnapshot dataSnapshot, @Nullable String s) {
}
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
}
Адаптер
public class WinnerAdapter extends Adapter<WinnerAdapter.WinnerViewHolder> {
private List<Winner> list;
class WinnerViewHolder extends ViewHolder {
ImageView image;
TextView name;
public WinnerViewHolder(View itemView) {
super(itemView);
this.name = itemView.findViewById(R.id.name);
this.image = itemView.findViewById(R.id.image);
}
}
public WinnerAdapter(List<Winner> list) {
this.list = list;
}
public WinnerViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
return new WinnerViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.winner_model_top, parent, false));
}
public void onBindViewHolder(WinnerViewHolder holder, int position) {
Winner winner = list.get(position);
Picasso.get()
.load(winner.photo_profile)
.transform(new CircleTransform())
.into(holder.image);
holder.name.setText(winner.name);
}
public int getItemCount() {
return this.list.size();
}
}
item
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="@+id/image"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_alignParentStart="true"
app:srcCompat="@drawable/ic_default_avatar_1" />
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/image"
android:layout_alignStart="@+id/image"
android:layout_alignEnd="@+id/image"
android:layout_marginStart="0dp"
android:fontFamily="sans-serif-medium"
android:textAlignment="center"
android:textColor="@color/white"
android:textSize="16sp" />
</RelativeLayout>