Привет,не получается сделать горизонтальный recycler.Есть два макета,один с recycler,другой с cardview,в которой находится image.И карточка должна заполняться этими image из массива(picasso).
public class HomeFragment extends Fragment {
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.homerecycler, container, false);
RecyclerView recyclerView=rootView.findViewById(R.id.rec1);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL,false));
recyclerView.setAdapter(new HorizontalAdapter(getContext()));
return rootView;
}
public interface FragmentListener {
}
public class HorizontalAdapter extends RecyclerView.Adapter<HorizontalAdapter.HorizontalViewHolder> {
private Context context;
private String[] items1={"http://topmemas.top/img/img/1517414160.jpg",
"http://topmemas.top/img/img/1518633309.jpg",
"http://topmemas.top/img/img/1517859960.jpg",};
public HorizontalAdapter(Context context){
this.context=context;
}
@Override
public HorizontalViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
LayoutInflater inflater=LayoutInflater.from(parent.getContext());
View view = inflater.inflate(R.layout.homefragment,parent,false);
return new HorizontalAdapter.HorizontalViewHolder(view);
}
@Override
public void onBindViewHolder(HorizontalAdapter.HorizontalViewHolder holder, int position) {
holder.image1.setImageURI(Uri.parse(items1[position]));
}
@Override
public int getItemCount() {
return items1.length;
}
public class HorizontalViewHolder extends RecyclerView.ViewHolder{
ImageView image1;
public HorizontalViewHolder(View view){
super(view);
image1=view.findViewById(R.id.imagepopul);
Picasso.with(context).load(items1[getPosition()]).placeholder(R.drawable.image).fit().into(image1);}
}
}