繁体   English   中英

为什么我的图像没有显示在带有 recyclerview 的图像 slider 中?

[英]why my images are not showing in image slider with recyclerview?

实际上,我是 android 开发的新手,我正在尝试使用 glide 和 recyclerview 将我的产品图像实现为带有名为“为什么不”的库的旋转木马。 但我看不到这样的照片。 我不知道如何实现这样的轮播,我做错了什么请帮助我。 请指导我有人请

我试图让它像这样在此处输入图像描述

我的设计 xml

   <androidx.cardview.widget.CardView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginStart="5dp"
    android:layout_marginTop="10dp"
    android:layout_marginEnd="5dp"
    app:cardCornerRadius="8dp"
    app:cardElevation="10dp"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <org.imaginativeworld.whynotimagecarousel.ImageCarousel
            android:id="@+id/carousel"
            android:layout_width="match_parent"
            android:layout_height="200dp"
            android:scaleType="centerCrop">

        </org.imaginativeworld.whynotimagecarousel.ImageCarousel>

        <TextView
            android:id="@+id/roomName"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="5dp"
            android:layout_marginTop="5dp"
            android:text="Room with kitchen"
            android:textColor="#232222"
            android:textSize="18sp"
            android:textStyle="bold" />

        <TextView
            android:id="@+id/roomRent"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="5dp"
            android:layout_marginTop="5dp"
            android:layout_marginBottom="5dp"
            android:text="Rent 4500/- month"
            android:textColor="#232222"
            android:textSize="18sp"
            android:textStyle="bold" />


    </LinearLayout>

</androidx.cardview.widget.CardView>

Model Class

public class Rooms {

public Rooms(String carousel, String title, int rent) {
    this.carousel = carousel;
    this.title = title;
    this.rent = rent;
}

private String carousel,title;
private int rent;

public String getCarousel() {
    return carousel;
}

public void setCarousel(String carousel) {
    this.carousel = carousel;
}

public String getTitle() {
    return title;
}

public void setTitle(String title) {
    this.title = title;
}

public int getRent() {
    return rent;
}

public void setRent(int rent) {
    this.rent = rent;
}

}

我的适配器 class

public class RoomsAdapter extends RecyclerView.Adapter<RoomsAdapter.RoomsViewHolder>{

Context context;
ArrayList<Rooms> rooms;

public RoomsAdapter(Context context, ArrayList<Rooms> rooms) {
    this.context = context;
    this.rooms = rooms;
}

@NonNull
@Override
public RoomsViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {

    return new RoomsViewHolder(LayoutInflater.from(context).inflate(R.layout.room_design_layout, parent, false));

}

@Override
public void onBindViewHolder(@NonNull RoomsViewHolder holder, int position) {
    Rooms room =  rooms.get(position);
    Glide.with(context)
            .load(room.getCarousel())
            .into(holder.carousel);
    holder.roomtitle.setText(room.getTitle());
    holder.roomrent.setText(String.valueOf(room.getRent()));


}

@Override
public int getItemCount() {
    return rooms.size();
}

public class RoomsViewHolder extends RecyclerView.ViewHolder{


    ImageView carousel;
    TextView roomtitle, roomrent;

    public RoomsViewHolder(@NonNull View itemView) {
        super(itemView);

        carousel = itemView.findViewById(R.id.carousel);
        roomtitle = itemView.findViewById(R.id.roomName);
        roomrent = itemView.findViewById(R.id.roomRent);
    }
}

}

这是使用WHY NOT IMAGE CAROUSEL库的轮播视图示例代码。 检查此代码

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM