我已经在Droid项目中实现了一个自定义的网页视图渲染器。问题是,在我的网页视图中显示了很多未使用的空间。请看图片。
XAML部件
<ContentPage.Content>
<StackLayout >
<ScrollView>
<StackLayout>
<StackLayout >
<Label Text="Be Happy" TextColor="Red" HorizontalOptions="Center" VerticalOptions="Start" />
<Label Text="This article is about the online encyclopedia." TextColor="Red" HorizontalOptions="Center" VerticalOptions="Start" />
<Button Text="Test" HorizontalOptions="Center" VerticalOptions="Start" />
<Label Text="Test" TextColor="Red" HorizontalOptions="Center" VerticalOptions="Start" />
<Label Text="This article is about the online encyclopedia." TextColor="Red" HorizontalOptions="Center" VerticalOptions="Start" />
<Button Text="Wikipedia" HorizontalOptions="Center" VerticalOptions="Start" />
<Label Text="Test" TextColor="Red" HorizontalOptions="Center" VerticalOptions="Start" />
<Label Text="This article is about the online encyclopedia." TextColor="Red" HorizontalOptions="Center" VerticalOptions="Start" />
<Button Text="Wikipedia" HorizontalOptions="Center" VerticalOptions="Start" />
<Label Text="Test" TextColor="Red" HorizontalOptions="Center" VerticalOptions="Start" />
<Label Text="This article is about the online encyclopedia." TextColor="Red" HorizontalOptions="Center" VerticalOptions="Start" />
<Button Text="Test" HorizontalOptions="Center" VerticalOptions="Start" />
</StackLayout>
<StackLayout x:Name="stackview" BackgroundColor="Red" />
</StackLayout>
</ScrollView>
</StackLayout>
</ContentPage.Content>
代码隐藏部件
public partial class WebViewTest : ContentPage
{
string url = "https://en.wikipedia.org/wiki/Wikipedia";
public WebViewTest( )
{
InitializeComponent();
var browser = new MyWebView
{
Source = url,
};
if (url == "")
{
browser.IsVisible = false;
}
else
{
stackview.Children.Add(browser);
}
}
}
对于自定义渲染器,我使用以下代码自定义渲染器代码
1条答案
按热度按时间guicsvcw1#
如果你只是想让webview修复你布局中的空白空间,你可以只得到空间的高度,并将其设置为webview的
HeightRequest
。比如说: