我希望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;
}
答案 0 :(得分:0)
替代解决方案:您可以通过编程方式实现
你可以尝试这个,自定义你想要的。
您可以AlertDialog
使用ProgressDialog
作为ProgressDialog
的以下代码。每当您显示进度对话框时,都需要调用此函数。
<强>代码:强>
public void setProgressDialog() {
int llPadding = 30;
LinearLayout ll = new LinearLayout(this);
ll.setOrientation(LinearLayout.HORIZONTAL);
ll.setPadding(llPadding, llPadding, llPadding, llPadding);
ll.setGravity(Gravity.CENTER);
LinearLayout.LayoutParams llParam = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
llParam.gravity = Gravity.CENTER;
ll.setLayoutParams(llParam);
ProgressBar progressBar = new ProgressBar(this);
progressBar.setIndeterminate(true);
progressBar.setPadding(0, 0, llPadding, 0);
progressBar.setLayoutParams(llParam);
llParam = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
llParam.gravity = Gravity.CENTER;
TextView tvText = new TextView(this);
tvText.setText("Loading ...");
tvText.setTextColor(Color.parseColor("#000000"));
tvText.setTextSize(20);
tvText.setLayoutParams(llParam);
ll.addView(progressBar);
ll.addView(tvText);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setCancelable(true);
builder.setView(ll);
AlertDialog dialog = builder.create();
dialog.show();
Window window = dialog.getWindow();
if (window != null) {
WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams();
layoutParams.copyFrom(dialog.getWindow().getAttributes());
layoutParams.width = LinearLayout.LayoutParams.WRAP_CONTENT;
layoutParams.height = LinearLayout.LayoutParams.WRAP_CONTENT;
dialog.getWindow().setAttributes(layoutParams);
}
}
<强>输出:强>