android - 如何通过Glide SDK 4.3.1在touchimageview中加载位图?

标签 android android-glide

我正在尝试将文件作为位图加载到 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/

相关文章:

java - Android 应用程序因图像而崩溃

android - 写入 ashmem/为什么 android 免费 ashmem?

android - Glide 无法加载服务器图片 url

android - 未能解决 glide,现在 3rd-party Gradle 插件可能是原因

c# - 如何从 sqlite 数据库中删除 Xamarin 中的表

Android:将 keystore 移交给不同的开发人员

android - 未以编程方式获得 SOAP Web 服务的正确响应

android - 如何在android中将来自服务器的图像显示到Glide中

android - 找不到 GeneratedAppGlideModule 错误

java - 我需要将多个图像下载到目录,以便可以离线访问内容