我正在尝试将文件作为位图加载到 TouchImageview 中。如果我使用普通 ImageView 而不是触摸 ImageView ,Glide 库能够从文件对象将图像加载到其中,但在触摸 ImageView Glide 无法加载图像的情况下。
还使用了以下代码:
Glide.with(this).asBitmap().load(file).into(new SimpleTarget<Bitmap>(250, 250) {
@Override
public void onResourceReady(Bitmap resource, Transition<? super Bitmap> transition) {
touchImageView.setImageBitmap(resource);
}
@Override
public void onLoadFailed(@Nullable Drawable errorDrawable) {
super.onLoadFailed(errorDrawable);
}
});
但是 OnLoadFailed()
被调用时 errorDrawable 为 null
。
最佳答案
好的,我刚刚找到有关 xml 的信息。请注意,您必须使用相对布局!
<RelativeLayout
android:layout_width="match_parent"
android:gravity="center"
android:layout_height="match_parent">
<my.zuhrain.kit.TouchImageView
android:layout_marginTop="20dp"
android:id="@+id/image_view_main"
android:layout_width="400dp"
android:layout_height="400dp" />
</RelativeLayout>
我们开始吧
storageReference.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
@Override
public void onSuccess(Uri uri) {
//things need to know
//USE RELATIVE LAYOUT!
Glide.with(getApplicationContext())
.asBitmap()
.load(uri)
.into(new SimpleTarget<Bitmap>() {
@Override
public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
touchImageView.setImageBitmap(resource);
}
});
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show();
}
});
关于android - 如何通过Glide SDK 4.3.1在touchimageview中加载位图?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47467826/