看不到进度条
can't see progress bar
我正在使用自定义对话框 class 来显示图像,由于某种原因,在图像完全加载之前,布局内部的进度条不可见。
我正在使用滑行,如果我调用 fullImageProgreesBar.setVisibility(View.VISIBLE);
我可以看到已加载图片上方的进度条。
我想在图片加载前显示进度条。
我的对话框class:
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>
没有为我解决这个问题的事情:
- 从 XML
更改 ProgressBar
海拔值
- 更改
ProgressBar
尺寸
- 更改
ConstaintLayout
中的顺序或元素(ProgressBar
在XML文件和编辑器中的ImageView
之上和之下)
如有任何帮助,我们将不胜感激。
您似乎忘记在 onResourceReady
中加载图像时将进度条的可见性更改为可见。改变这个
fullImageProgreesBar.setVisibility(View.INVISIBLE);
至此
fullImageProgreesBar.setVisibility(View.VISIBLE);
我正在使用自定义对话框 class 来显示图像,由于某种原因,在图像完全加载之前,布局内部的进度条不可见。
我正在使用滑行,如果我调用 fullImageProgreesBar.setVisibility(View.VISIBLE);
我可以看到已加载图片上方的进度条。
我想在图片加载前显示进度条。
我的对话框class:
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>
没有为我解决这个问题的事情:
- 从 XML 更改
- 更改
ProgressBar
尺寸 - 更改
ConstaintLayout
中的顺序或元素(ProgressBar
在XML文件和编辑器中的ImageView
之上和之下)
ProgressBar
海拔值
如有任何帮助,我们将不胜感激。
您似乎忘记在 onResourceReady
中加载图像时将进度条的可见性更改为可见。改变这个
fullImageProgreesBar.setVisibility(View.INVISIBLE);
至此
fullImageProgreesBar.setVisibility(View.VISIBLE);