Я использую адаптер для отображения списка значков профиля. Я использую скольжение для отображения изображений. Но проблема в том, что он загружает профиль по умолчанию и не загружает URL-адрес из ответа в первый раз.
Когда я перехожу на предыдущую страницу и перехожу на страницу второй раз, она загружает URL-адрес.
@Override
public void onBindViewHolder(RetailerStatusViewHolder holder, int position) {
if (retailerList.getImgUrl()!=null){
Glide.with(context)
.load(retailerList.getImgUrl())
.placeholder(R.drawable.ic_default_profile)
.error(R.drawable.ic_default_profile)
.into(((holder.circleImageView)));
}
}
Я тоже пробовал давать context.getApplicationContext(), но изображения загружаются только второй раз
compile 'com.github.bumptech.glide:glide:3.8.0'
<com.customviews.CircleImageView
android:id = "@+id/recycle_profile"
android:layout_width = "30dp"
android:layout_height = "30dp"
android:layout_gravity = "center"
android:layout_marginLeft = "16dp"
android:src = "@drawable/ic_default_profile"/>
Glide занимает некоторое время, чтобы загрузить изображение, и это также создает проблемы, когда вы загружаете Circular ImageViewСм. Эту ссылку, это поможет вам найти проблему.
попробуй это:
XML-код:
<set xmlns:android = "http://schemas.android.com/apk/res/android">
<alpha
android:duration = "800"
android:fromAlpha = "0.0"
android:interpolator = "@android:anim/decelerate_interpolator"
android:toAlpha = "1.0"/>
Класс Java:
public static void loadImage(final Activity context, ImageView imageView, String url, int placeHolderUrl, int errorImageUrl) {
if (context == null || context.isDestroyed()) return;
//placeHolderUrl=R.drawable.ic_user;
//errorImageUrl=R.drawable.ic_error;
Glide.with(context) //passing context
.load(getFullUrl(url)) //passing your url to load image.
.placeholder(placeHolderUrl) //this would be your default image (like default profile or logo etc). it would be loaded at initial time and it will replace with your loaded image once glide successfully load image using url.
.error(errorImageUrl)//in case of any glide exception or not able to download then this image will be appear . if you won't mention this error() then nothing to worry placeHolder image would be remain as it is.
.diskCacheStrategy(DiskCacheStrategy.ALL) //using to load into cache then second time it will load fast.
.animate(R.anim.fade_in) // when image (url) will be loaded by glide then this face in animation help to replace url image in the place of placeHolder (default) image.
.fitCenter()//this method help to fit image into center of your ImageView
.into(imageView); //pass imageView reference to appear the image.
}
Добавьте эту строку в свою деятельность:
Utils.loadImage(YourClassName.this,mImageView,url,R.drawable.ic_user,R.drawable.ic_error);
Во фрагменте:
Utils.loadImage(getActivity,mImageView,url,R.drawable.ic_user,R.drawable.ic_error);
Я думаю это поможет тебе
Glideзаймет некоторое время, чтобы загрузить изображение с URL-адреса