【发布时间】:2020-04-03 00:25:06
【问题描述】:
让我先说对不起,如果这已经在某个地方得到了回答,我搜索了很长时间,但找不到有效的答案。
所以根据标题,我有一个非常简单的应用程序,它实际上只有一个页面,应该显示来自 URI 的一张图像,仅此而已。由于某种原因,在物理设备或模拟器上部署时,图像都不会显示。图片工作正常,它只是来自网络 (http://thumbs.dreamstime.com/z/watercolor-autumn-forest-landscape-sunset-hand-drawn-painting-fantasy-art-nature-beautiful-background-gouache-153834924.jpg) 的随机图片。我附加了 ActivityIndicator,它在一秒钟后停止旋转,所以我假设图像已加载,因此应用程序未连接到网络并只是图像渲染不是问题...
我尝试将 Android 选项 -> 高级 -> HttpClient 实现设置为托管,将 SSL/TLS 实现设置为原生 TLS 1.2+,以及 Android 清单 -> 所需权限 -> 互联网。都没有帮助。我尝试使用 http:// 和 https://,也没有结果。我现在很困惑。
这是我的 App.xaml.cs:
using System;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
using App1.Services;
using App1.Views;
namespace App1
{
public partial class App : Application
{
public App()
{
InitializeComponent();
DependencyService.Register<MockDataStore>();
MainPage = new ImagePage();
}
}
}
这是 ImagePage.xaml.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
namespace App1
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class ImagePage : ContentPage
{
public ImagePage()
{
InitializeComponent();
var imageSource = new UriImageSource { Uri = new Uri("http://thumbs.dreamstime.com/z/watercolor-autumn-forest-landscape-sunset-hand-drawn-painting-fantasy-art-nature-beautiful-background-gouache-153834924.jpg") };
imageSource.CachingEnabled = false;
image.Source = imageSource;
}
}
}
这是此页面的 xaml:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Class="App1.ImagePage">
<AbsoluteLayout>
<ActivityIndicator IsRunning="{Binding Source={x:Reference image}, Path=IsLoading}" AbsoluteLayout.LayoutBounds="0.5, 0.5, 100, 100" AbsoluteLayout.LayoutFlags="PositionProportional"/>
<Image IsVisible="True" x:Name="image"/>
</AbsoluteLayout>
</ContentPage>
我将不胜感激任何帮助:)。正如我所说,这非常简单,我不知道为什么此时这不起作用。
【问题讨论】:
-
那个 url 返回一个 HTTP 301。我认为你选择了一个不好的例子
标签: c# android image xamarin xamarin.forms