FFImageLoading : 加载到 ImageButton [英] FFImageLoading : load into an ImageButton

查看:24
本文介绍了FFImageLoading : 加载到 ImageButton的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Xamarin.Android 中,要使用 FFImageLoading 加载图像,必须使用 ImageViewAsync 而不是标准 ImageView.

In Xamarin.Android, to load an image using FFImageLoading, a ImageViewAsync must be used instead of a standard ImageView.

如果我想将图像加载到 ImageButton 中,我找不到可以使用的内容.没有找到ImageButtonAsync".

I couldn't find what I can use if I wanna load my image into an ImageButton. Didn't find an "ImageButtonAsync".

推荐答案

AFAIK 没有特定的 ImageButton 与 FFImageLoading 一起使用,但您可以直接使用 ImageViewAsync 设置它作为 android:clickable="true" 并添加点击事件.

AFAIK there is no particular ImageButton to use with FFImageLoading but you can use directly an ImageViewAsync set it as android:clickable="true" and add the click event.

正如所述这里 ImageButton 只是一个 ImageView 默认情况下具有非空背景,并且 ImageButton.onSetAlpha() 方法始终返回 false,设置了 scaleType居中,它总是被夸大为可聚焦.因此,如果您需要该行为,您可以添加它.

And as stated here an ImageButton is just an ImageView that has a non-null background by default and also, ImageButton.onSetAlpha() method always returns false, scaleType is set to center and it's always inflated as focusable. So if you need that behaviour you can add it.

另一种方法是创建可以处理 FFImageLoading 图像加载的自定义 ImageButton.为此,您可以从 ImageViewAsync 继承并添加之前段落中解释的行为.这样您就可以直接使用 FFImageLoading API,因为这个自定义控件继承了 ImageViewAsync.

Another way would be you to create your custom ImageButton that can handle FFImageLoading image loading. For that you can inherit from ImageViewAsync and add the behaviours explained in the paragraph before. So that you can use the FFImageLoading API directly as this custom controls inherits ImageViewAsync.

除此之外,您还可以添加自定义加载逻辑,如here 继承自 ImageLoaderTask 并像 ImageService.Instance.LoadImage(customImageTask)

Instead of that you can also add your custom loading logic as explained here inheriting from ImageLoaderTask and call it like ImageService.Instance.LoadImage(customImageTask)

最后的另一种方法(但很hackish 且性能不佳)是创建一个 ImageViewAsync 来保存 FFImageLoading 的结果,并在 Success 回调中设置 ImageButton<中的 Drawable:

Finally another way (but hackish and non-performant) would be to create an ImageViewAsync just to hold the result of the FFImageLoading and on the Success callback set the Drawable in the ImageButton:

var myImageButton = myView.FindViewById<ImageButton>(Resource.Id.my_image_button);
var myImageView = new ImageViewAsync(this); // this is the context
ImageService.Instance.LoadUrl(this.Source[position].LogoImagePath)
                .Success(() => myImageButton.SetImageDrawable(myImageView.Drawable))
                .Into(myImageView);

HIH,如果您需要任何帮助,请告诉我

HIH and if you need any help let me know

这篇关于FFImageLoading : 加载到 ImageButton的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆