Я хочу показать Progressbar
, когда ImageView
загружает изображение с Glide внутри ViewPager
.
. ProgressBar
действительно показывает, когда изображениезагружен он уходит, но не показывает изображение.и когда пользователь уменьшает изображение, появляется немного ImageView.
Я ранее использовал ProgressDialog
, который работал нормально, но так как он устарел, я не могу его использовать.
Любая помощьбудет оценен.
Вот мой макет для PagerAdapter:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<starter.umair.locshare.TouchImageView
android:id="@+id/mTouchImageViewSlider"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ProgressBar
android:id="@+id/mProgressBarImageViewer"
style="?android:attr/progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:visibility="visible" />
</RelativeLayout>
А это instantiateItem
в PagerAdapter.Java
:
@NonNull
@Override
public Object instantiateItem(@NonNull ViewGroup container, final int position) {
mLayoutInflater = (LayoutInflater) mContext.getSystemService(LAYOUT_INFLATER_SERVICE);
View view = mLayoutInflater.inflate(R.layout.swipe_layout, container, false);
final TouchImageView imageView = (TouchImageView) view.findViewById(R.id.mTouchImageViewSlider);
final ProgressBar p = (ProgressBar) view.findViewById(R.id.mProgressBarImageViewer);
Glide.with(mContext)
.asBitmap()
.load(mListUri.get(position))
.into(new SimpleTarget<Bitmap>(com.bumptech.glide.request.target.Target.SIZE_ORIGINAL,
com.bumptech.glide.request.target.Target.SIZE_ORIGINAL) {
@Override
public void onLoadStarted(@Nullable Drawable placeholder) {
super.onLoadStarted(placeholder);
p.setVisibility(View.VISIBLE);
}
@Override
public void onResourceReady(Bitmap resource, Transition<? super Bitmap> transition) {
p.setVisibility(View.GONE);
imageView.setImageBitmap(resource);
}
@Override
public void onLoadFailed(@Nullable Drawable errorDrawable) {
super.onLoadFailed(errorDrawable);
p.setVisibility(View.GONE);
Toast.makeText(mContext, "Connection Problem.", Toast.LENGTH_SHORT).show();
finish();
}
});
container.addView(view);
return view;
}