如何配置Xamarin Webview根据html内容显示自动高度? 我正在Xamarin开发一个新闻应用程序,我有这个问题,因为webview强制我通知高度和宽度来显示信息,因为我的内容是动态的,(总是更改)最终成为屏幕上的空白区域!
对不起英文,我用google翻译!
谢谢!
代码:PostView.cs
namespace AppNewsPlay.Views
{
public partial class PostView : TabbedPage
{
private int object_id;
// Criando a Listagem de Ultimas Noticias Playstation
List<PostViewModels> UPost;
public TabbedPage Detail { get; private set; }
public PostView(int object_id)
{
this.object_id = object_id;
UPost = new List<PostViewModels>();
ObterPost();
InitializeComponent();
}
private async void ObterPost()
{
var resp = string.Empty;
try
{
var uri = new HttpClient()
{
BaseAddress = new Uri("http://api.newsplay.com.br")
};
var url = "/api/post/" + this.object_id;
var result = await uri.GetAsync(url);
if (!result.IsSuccessStatusCode)
{
await DisplayAlert("Erro de Conexão", "Não foi possível obter as notícias do servidor, Tente novamente mais tarde!", "OK");
return;
}
resp = await result.Content.ReadAsStringAsync();
}
catch (Exception ex)
{
await DisplayAlert("Erro de Conexão com o Servidor", ex.Message, "OK");
return;
}
// transformando o retorno em objeto através do json e deserealize e retornando em lista
var UPost = JsonConvert.DeserializeObject<List<PostViewModels>>(resp);
var browser = new WebView();
// var htmlsource = new UrlWebViewSource();
foreach (var item in UPost)
{
var html = item.Guid;
browser.Source = html;
}
// Adicionando os itens ao ListView na Home.xaml - Aba Playstation*/
PostViewList.ItemsSource = UPost;
// ProgressLoader.IsRunning = false;
}
代码:PostView.xaml
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="AppNewsPlay.Views.PostView"
Title="Voltar"
Icon=""
BarBackgroundColor="#1c9e33"
>
<TabbedPage.Children>
<ContentPage Title="Notícia" Icon="ic_filter_list_black_24dp.png">
<ContentPage.Content >
<StackLayout
Spacing="20">
<ListView x:Name="PostViewList"
HasUnevenRows="True"
SeparatorColor="White"
SeparatorVisibility="Default"
>
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout
Padding="20"
Orientation="Vertical"
>
<Label x:Name="Post_title" Text="{ Binding Post_title }"
FontSize="20"
FontAttributes="Bold"
HorizontalTextAlignment="Center"
/>
<Label x:Name="Post_ad" Text="{Binding Post_ad}"
FontSize="12"
HorizontalTextAlignment="Center"
/>
<WebView HorizontalOptions= "FillAndExpand"
VerticalOptions="FillAndExpand"
HeightRequest="3500"
WidthRequest="650"
x:Name="browser"
Source="{Binding Guid}"
>
</WebView>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
</ContentPage.Content>
</ContentPage>
</TabbedPage.Children>
</TabbedPage>