如何通过Glide SDK 4.3.1在TouchImageView中加载位图?

3

我正在尝试将一个文件作为位图加载到TouchImageview中。如果我使用普通的ImageView而不是TouchImageView,Glide库可以从文件对象中加载图像,但在TouchImageView中,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

你好,你解决了你的问题吗? - Ticherhaz FreePalestine
1个回答

1

好的,我刚刚了解到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();
            }
        });

什么是storageReference? - reza_khalafi
1
@reza_khalafi storageReference 是来自 Firebase 的。我从 Firebase 获取了 URL。这是我的情况。 - Ticherhaz FreePalestine

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接