我使用滑动库将服务器中的图像数组加载到RecyclewView
。
我有一个名为ImagePreviewActivity
的活动,我希望缩略图中的图像在点击时显示。
单击某个项目或图像时,我想将该图像从缩略图加载到另一个活动中。我如何实现这一目标?
GalleryAdapter.java
public class GalleryAdapter extends RecyclerView.Adapter<GalleryAdapter.MyViewHolder> {
ArrayList<Album> arrayList = new ArrayList<>();
Activity activity;
public GalleryAdapter(ArrayList<Album> arrayList, Context context) {
this.arrayList = arrayList;
activity = (Activity) context;;
}
@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_view, parent,false);
return new MyViewHolder(view);
}
@Override
public void onBindViewHolder(final MyViewHolder holder, int position) {
holder.Thumbnail.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(activity, ImagePreviewActivity.class);
activity.startActivity(intent);
}
});
//url path of images
String path = Config.img_path + arrayList.get(position).getId()+".jpg";
Glide.with(activity).load(path).placeholder(R.drawable.placeholder).error(R.drawable.error).listener(new RequestListener<String, GlideDrawable>() {
@Override
public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
holder.progressBar.setVisibility(View.GONE);
return false;
}
@Override
public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
return false;
}
}).into(holder.Thumbnail);
}
@Override
public int getItemCount(){
return arrayList.size();
}
public static class MyViewHolder extends RecyclerView.ViewHolder {
ImageView Thumbnail;
TextView Title;
String img_path;
public MyViewHolder(View itemView) {
super(itemView);
Thumbnail = itemView.findViewById(R.id.thumbnail);
Title = itemView.findViewById(R.id.album_title);
img_path = Config.img_path +".jpg";
}
}
}
ImageActivityPreview.java
ImageView imageView = findViewById(R.id.image_preview);
Intent intent = getIntent();
String image_url = intent.getStringExtra("imagerurl");
Glide.with(this).load(image_url).into(imageView);
答案 0 :(得分:0)
只需使用
将点击后的图片的网址发送到下一个活动intent.putExtra("imgURL",path);
方法然后在该活动中使用滑动加载图像。据我所知,如果图像是通过滑行下载的,那么它将保留在缓存中。