我正在使用此代码显示带有网址的图片
的.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" x:Class="LandAHand.VolunteerView">
<ContentPage.Content>
<AbsoluteLayout BackgroundColor="Maroon">
<Image x:Name="backgroundImage" AbsoluteLayout.LayoutBounds="0,0,1,1" AbsoluteLayout.LayoutFlags="All" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" Aspect="AspectFill"/>
</AbsoluteLayout>
</ContentPage.Content>
</ContentPage>
的.cs
using System;
using System.Collections.Generic;
using Xamarin.Forms;
namespace LandAHand
{
public partial class VolunteerView : ContentPage
{
public VolunteerView()
{
InitializeComponent();
backgroundImage.Source = new UriImageSource
{
Uri = new Uri("https://s9.postimg.org/aq1jt3fu7/handshake_87122244_std.jpg"),
CachingEnabled = true,
CacheValidity = new TimeSpan(5, 0, 0, 0)
};
}
}
}
此代码已成功与iOS配合使用,但未与Android配合使用。
答案 0 :(得分:5)
嗯,你可以通过你的Xaml更容易地做这件事,只需要像你一样制作你的xaml
<Image x:Name="backgroundImage" Source="https://s9.postimg.org/aq1jt3fu7/handshake_87122244_std.jpg" AbsoluteLayout.LayoutBounds="0,0,1,1" AbsoluteLayout.LayoutFlags="All" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" Aspect="AspectFill"/>
删除后面代码中的相关代码。默认情况下,现金支付已启用24小时
答案 1 :(得分:0)
它不起作用,因为您使用的是https网址。 要修复它,您应该像这样配置您的Android项目: 在项目选项> Android选项中,单击高级选项 HttpClient实现:选择Android SSL / TLS实施:选择本机TLS 1.2 +
https://docs.microsoft.com/en-us/xamarin/android/app-fundamentals/http-stack?tabs=windows
并更新所有Xamarin.Android软件包