У меня горизонтальный RecyclerView, у которого есть GridView. Когда я прокручиваю RecyclerView, одновременно появляются 2 элемента. Я просто хочу показать элемент в текущей позиции.
Activity:
recyclerView = findViewById(R.id.recyclerView);
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this, RecyclerView.HORIZONTAL, false);
recyclerView.setHasFixedSize(false);
recyclerView.setLayoutManager(linearLayoutManager);
recyclerView.setAdapter(new MyRecyclerViewAdapter(this, getTotalCount()));
Мой адаптер:
public class MyRecyclerViewAdapter extends RecyclerView.Adapter<MyRecyclerViewAdapter.MyViewHolder> {
private int count;
private Context context;
public MyRecyclerViewAdapter(Context context, int count) {
this.context = context;
this.count = count;
}
@NonNull
@Override
public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
return new MyViewHolder(ViewUtil.inflate(LayoutInflater.from(context), parent, R.layout.my_recyclerView));
}
@Override
public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
MyGridViewAdapter myGridViewAdapter = new MyGridViewAdapter(position);
holder.gridView.setAdapter(myGridViewAdapter);
}
@Override
public int getItemCount() {
return count;
}
static class MyViewHolder extends RecyclerView.ViewHolder {
private GridView gridView;
MyViewHolder(View itemView) {
super(itemView);
gridView = itemView.findViewById(R.id.grid);
}
}