我正在使用自定义Dialog类来显示图像,并且由于某种原因,直到图像完全加载后,布局内部的进度条才可见。
我正在滑行,如果我打fullImageProgreesBar.setVisibility(View.VISIBLE);
我可以在已加载的图像上方看到进度条。
我想在加载图像之前显示进度条。
我的对话框类:
public class FullSizeImageDialog extends Dialog {
private ImageView imageView;
private ProgressBar fullImageProgreesBar;
private Context dialogContext;
public FullSizeImageDialog(@NonNull Context context) {
super(context);
setContentView(R.layout.full_size_image_dialog);
dialogContext = context;
imageView = findViewById(R.id.full_size_image);
fullImageProgreesBar = findViewById(R.id.fullImageProgreesBar);
}
public void setImageFullSize(Uri imageUri) {
Glide.with(dialogContext).load(imageUri)
.listener(new RequestListener<Uri, GlideDrawable>() {
@Override
public boolean onException(Exception e, Uri model, Target<GlideDrawable> target, boolean isFirstResource) {
fullImageProgreesBar.setVisibility(View.INVISIBLE);
Toast.makeText(dialogContext, "No image available", Toast.LENGTH_SHORT).show();
return false;
}
@Override
public boolean onResourceReady(GlideDrawable resource, Uri model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
fullImageProgreesBar.setVisibility(View.INVISIBLE);
return false;
}
}).into(imageView);
}
}
该对话框的布局文件:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ProgressBar
android:id="@+id/fullImageProgreesBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:elevation="6dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/full_size_image" />
<ImageView
android:id="@+id/full_size_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:background="@drawable/new_question"
android:fitsSystemWindows="true"
android:scaleType="fitXY"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
无法为我解决此问题的东西:
ProgressBar
高程值ProgressBar
的大小ConstaintLayout
内的顺序或元素(ProgressBar
在XML文件和编辑器中的ImageView
上方和下方)任何帮助将不胜感激。
答案 0 :(得分:1)
好像您忘记了在onResourceReady
中加载图像时将进度条的可见性更改为可见。改变这个
fullImageProgreesBar.setVisibility(View.INVISIBLE);
对此
fullImageProgreesBar.setVisibility(View.VISIBLE);