Android 在RecylerView中显示内容及其相应的图像
我有一个用于recyclerView的适配器MyAdapter.java 我有row view Model.xml 如何在适配器类的onBindViewHolder上显示图像/媒体阵列Android 在RecylerView中显示内容及其相应的图像,android,android-recyclerview,Android,Android Recyclerview,我有一个用于recyclerView的适配器MyAdapter.java 我有row view Model.xml 如何在适配器类的onBindViewHolder上显示图像/媒体阵列 有人能给我一个主意吗?在这里,我分享我的工作方法,你可以查看 如何在一行中显示一组图像 在一行中添加水平滚动视图 <LinearLayout android:id="@+id/linearLayout3" android:layout_width="0dp" android:lay
有人能给我一个主意吗?在这里,我分享我的工作方法,你可以查看 如何在一行中显示一组图像 在一行中添加水平滚动视图
<LinearLayout
android:id="@+id/linearLayout3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="2dp"
android:background="@color/white"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
/* OTHER VIEWS */
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp">
<LinearLayout
android:id="@+id/imgEvents"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" />
</HorizontalScrollView>
</LinearLayout>
根据需要调整imageview参数
票据副本的可能副本。显示行中包含其他内容的单个图像。如果要按recylerview中的行数显示图像数组,则“我的显示”中的图像列表包含其他内容。。或者你只有一行是水平滚动的..我不明白你@MohamedMohaidenahyou想要一行中包含一组图像的垂直recylerview,或者你想要一行中的水平recylerview..非常感谢!尝试你的解决方案。我可以使用带另一个适配器的Recyler视图来渲染图像吗?@Navigator我找不到你了?我的意思是不要使用带线性布局的水平滚动视图,我们可以在线性布局中以程序方式添加图像。我们可以使用recylerview而不是linearlayout来显示图像吗?您可以在recylerview中使用recylerview而不是scrollview,并使用单独的适配器。。
<LinearLayout
android:id="@+id/linearLayout3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="2dp"
android:background="@color/white"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
/* OTHER VIEWS */
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp">
<LinearLayout
android:id="@+id/imgEvents"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" />
</HorizontalScrollView>
</LinearLayout>
private View getImageView(String url) {
ImageView imageView = new ImageView(mContext);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
lp.setMargins(0, 0, 10, 0);
imageView.setLayoutParams(lp);
Glide.with(mContext).load(url).into(imageView);
return imageView;
}
public class MyViewHolder extends RecyclerView.ViewHolder {
private LinearLayout imgEvevts;
// Add other views also
public MyViewHolder(View itemView) {
super(itemView);
imgEvevts = itemView.findViewById(R.id.imgEvents);
}
}
@Override
public void onBindViewHolder(final MyViewHolder holder, int position) {
String[] event_images = item.getImages(); //get array of strings here & declare string array at top.
for (int i = 0;i < event_images.length;i++)
{
holder.imgEvevts.addView(getImageView(event_images[i]));
}
}