我使用循环视图和毕加索,但当更新数据回收视图picasso没有加载图片android

时间:2018-04-23 08:51:08

标签: android image load picasso

毕加索没有加载图片。 这是我的代码屏幕截图:

enter image description here

当我滚动回收图像不顺畅 希望大家帮助我

2 个答案:

答案 0 :(得分:0)

您可以在recyclerview中添加平滑滚动条以实现平滑滚动。您必须按照以下步骤操作:

1)只需创建平滑的滚动条。

RecyclerView.SmoothScroller smoothScroller = new LinearSmoothScroller(context) {
    @Override protected int getVerticalSnapPreference() {
         return LinearSmoothScroller.SNAP_TO_START;
    }
};

2)将平滑滚动条设置为布局管理器,如下所示。

layoutManager.startSmoothScroll(smoothScroller);

现在全部设定!!

您的recyclerview将顺利滚动。

希望它有所帮助!!

答案 1 :(得分:0)

尝试使用此代替代码并为图像视图设置固定高度,如果不是图像视图,则将高度设置为0,并且在加载图像后尺寸将增加

if(message.getMessageType().equals(MesageType.Text)){
    holder.imgPic.setVisibility(View.GONE);
    holder.txtMessage.setVisibility(View.VISIBLE);
    holder.txtMessage.setText(message.getMessageText());
}else{
    holder.imgPic.setVisibility(View.VISIBLE);
    holder.txtMessage.setVisibility(View.GONE);
    holder.txtMessage.setText("");
    Picasso.with(context).load(message.getUrl_downloadd()).into(holder.imgPic);
}

Firebase听众:

/*Child listener for chat*/
private final ChildEventListener childEventListener = new ChildEventListener() {
    @Override
    public void onChildAdded(DataSnapshot snapShot, String s) {
        //append the message to exiting an displayed
        if (snapShot != null && snapShot.getValue() != null && !snapShot.getKey().equalsIgnoreCase("users")) {
            Message message = snapShot.getValue(Message.class);
            if (message != null && !messageKeys.contains(snapShot.getKey())) {
                messageKeys.add(snapShot.getKey());
                message.setKey(snapShot.getKey());
                //add your new message to adapter
            }
        }

    }

    @Override
    public void onChildChanged(DataSnapshot snapShot, String s) {

    }

    @Override
    public void onChildRemoved(DataSnapshot snapShot) {

    }

    @Override
    public void onChildMoved(DataSnapshot dataSnapshot, String s) {

    }

    @Override
    public void onCancelled(DatabaseError databaseError) {

    }
};
//value added listener for chat
private final ValueEventListener valueEventListener = new ValueEventListener() {
    @Override
    public void onDataChange(DataSnapshot data) {
        List<Message> messages = new ArrayList<>();
        if (data != null && data.getValue() != null && data.getChildrenCount() > 0) {
            /*add all  messages to lis and displayed*/

            for (DataSnapshot snapShot : data.getChildren()) {
                if (snapShot != null && snapShot.getValue() != null && !snapShot.getKey().equalsIgnoreCase("users")) {
                    Message message = snapShot.getValue(Message.class);
                    if (message != null && !messageKeys.contains(snapShot.getKey())) {
                        messageKeys.add(snapShot.getKey());
                        message.setKey(snapShot.getKey());
                        messages.add(message);
                    }
                }
            }

        }
     //display your message on adapter

        //removed ValueEventListener from firebase
             getQueryForMessages().removeEventListener(this);
        //added child change listener to firebase
                   getQueryForMessages().addChildEventListener(childEventListener);
    }

    @Override
    public void onCancelled(DatabaseError databaseError) {

    }
};