图像+视频混合在RecyclerView中

时间:2016-11-27 15:04:56

标签: java android imageview android-recyclerview android-videoview

我试图检查VideoView中的图片和视频供应情况,但挑战是ImageView是唯一一个在所有商品列表中可见,VideoView不可见我想要的是检查ImageView中的图像是否存在于Videoview GOES ,以及当ImageView RecyclerView 中的视频可用时去

正在开发一个发布视频和图片的应用并在同一boolean hasDrawable = (viewHolder.imagePost.getDrawable()!= null); String hasVideo_string =(String)viewHolder.videoLayout.getTag(); boolean hasVideo = Boolean.parseBoolean(hasVideo_string); if(hasDrawable){ viewHolder.setTitle(model.getEventTitle()); viewHolder.setDesc(model.getEventDescription()); viewHolder.setImage(c, model.getEventImage()); viewHolder.videoLayout.setVisibility(View.INVISIBLE); } else if(hasVideo) { viewHolder.setTitle(model.getEventTitle()); viewHolder.setDesc(model.getEventDescription()); viewHolder.setVideo(c, model.getEventVideo()); viewHolder.imagePost.setVisibility(View.GONE); } 中检索它们,所以请帮助我如何实现这一目标

以下是我的代码,但它不起作用:

ViewHolder

这就是我在public void setImage(final Context c,final String imageUrl){ // Picasso.with(c).load(imageUrl).error(R.mipmap.add_btn).fit().centerInside().placeholder(R.mipmap.add_btn) .networkPolicy(NetworkPolicy.OFFLINE).into(imagePost, new Callback() { @Override public void onSuccess() { } @Override public void onError() { //Reloading an image again ... Picasso.with(c).load(imageUrl).error(R.mipmap.add_btn).placeholder(R.mipmap.add_btn) .into(imagePost); } }); }

中设置图像和视频的方法
public void setVideo(final Context c, final String videoUrl){

   // videoLayout.setActivity(this);
   // videoLayout.setActivity(get);

    Uri videoUri = Uri.parse(videoUrl);
    try {
        videoLayout.setVideoURI(videoUri);
        videoLayout.setTag(videoUrl);

    } catch (IOException e) {
        e.printStackTrace();
    }
}

和视频(我使用了一个名为FullscreenVideoLayout的库,它像VideoView一样,但定制很多)

ViewHolder

这是完整的public static class BlogViewHolder extends RecyclerView.ViewHolder{ View mView; private ImageView imagePost; private FullscreenVideoLayout videoLayout; private VideoView videoView; public BlogViewHolder(View itemView) { super(itemView); mView=itemView; imagePost =(ImageView)mView.findViewById(R.id.post_image); videoLayout = (FullscreenVideoLayout) mView.findViewById(R.id.post_video); } public void setTitle(String title){ TextView post_title = (TextView)mView.findViewById(R.id.post_title); post_title.setText(title); } public void setDesc(String desc){ TextView post_desc = (TextView)mView.findViewById(R.id.post_desc); post_desc.setText(desc); } public void setImage(final Context c,final String imageUrl){ // Picasso.with(c).load(imageUrl).error(R.mipmap.add_btn).fit().centerInside().placeholder(R.mipmap.add_btn) .networkPolicy(NetworkPolicy.OFFLINE).into(imagePost, new Callback() { @Override public void onSuccess() { } @Override public void onError() { //Reloading an image again ... Picasso.with(c).load(imageUrl).error(R.mipmap.add_btn).placeholder(R.mipmap.add_btn) .into(imagePost); } }); } public void setVideo(final Context c, final String videoUrl){ // videoLayout.setActivity(this); // videoLayout.setActivity(get); Uri videoUri = Uri.parse(videoUrl); try { videoLayout.setVideoURI(videoUri); videoLayout.setTag(videoUrl); } catch (IOException e) { e.printStackTrace(); } } } 课程

%USERPROFILE%\.gradle

1 个答案:

答案 0 :(得分:1)

我发现您正在使用Firebase,因此您获得了视频和图片UrlsgetEventImage()的{​​{1}},只需查看getEventVideo()即可如果它们为空并删除了UrlsImageView的可见性。

下面是示例代码,试试这个:

VideoView

希望它适合你。