【发布时间】:2020-03-09 10:28:22
【问题描述】:
Xamarin.Forms - Android。 我在 Android 平台上使用 Button Renderer 将图像添加到 Android.Widget.Button。 Image 文件存储在 Assets 文件夹中,而不是通常的 Drawable 文件夹中。 我在 XAML 中正常设置按钮的 ImageSource,然后在渲染器中获取图像位置并在资产文件夹中搜索它。 可绘制对象已正确创建并通过检查匹配的宽度和高度等来确认,但它只是没有显示在按钮本身上。 图像文件具有 AndroidAsset 的构建操作,但我也尝试了 AndroidResource,但它仍然无法正常工作。
FileImageSource fis = (FileImageSource)Element.ImageSource;
Stream stream = context.Assets.Open("images/" + fis.File);
Drawable d = Drawable.CreateFromStream(stream, null);
stream.Close();
Control.SetCompoundDrawablesWithIntrinsicBounds(null, d, null, null);
【问题讨论】:
标签: c# android xamarin xamarin.forms xamarin.android