[英]Show image from URL with Xamarin.Forms
我正在使用此代碼顯示來自 URL 的圖像
<?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>
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。
那么你可以用你的 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小時
它不起作用,因為您使用了 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 包
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.