It is used for finishing operation after loading the picture, such as using Glide in ListView or RecycleView after loading the picture, the picture can not display completely by itself, but can display completely by manual swipe. This is because the picture loading is asynchronous, and the Adapter has been updated before the picture rendering is completed. So the ListView does not take into account the height of the image when redrawing, because it is likely that the image has not been rendered yet. Consider using a callback interface to scroll the ListView to the bottom after the image is loaded

Glide.with(context).load(content_split) .listener(new RequestListener<String, GlideDrawable>() { @Override public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) { return false; } @Override public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, Boolean isFromMemoryCache, Boolean isFirstResource) {listener.chatpngready (resource); return false; } }) .into(imageView);Copy the code

If it is in the Adapter for image loading can be defined in accordance with the above way in the adapter callback interface, in the image loading callback method to perform the listView or recycleView slide to the bottom operation

  public interface GlideReadyListener{
        void chatPngReady(GlideDrawable resource);
    }
Copy the code
@Override public void chatPngReady(GlideDrawable resource) { if (mListViewMsgItems ! = null && mListViewMsgItems. GetCount () > 0) {/ / picture loaded when a listview slide to the bottom again mListViewMsgItems.setSelection(mListViewMsgItems.getBottom()); }}Copy the code

Or you can use RxJava delay operators delay or timer, but this depends on a better network environment, or the delay time is set longer, but the user experience is not good.