Xamarin Forms WebView高度与HTML内容相关

6

我有一个加载了3个gif的html页面的WebView。我希望WebView能够自适应HTML内容大小。这种情况是否可能?在WebView下面,我使用一个标签显示一些说明。

   <Grid>
     <Grid>
       <Grid.RowDefinitions>
         <RowDefinition Height="auto"/>
         <RowDefinition Height="*"/>
         <RowDefinition Height="*"/>
       </Grid.RowDefinitions>
       <Grid Grid.Row="0" >
         <Grid.RowDefinitions>
           <RowDefinition/>
         </Grid.RowDefinitions>
         <Grid.ColumnDefinitions>
           <ColumnDefinition Width="*"/>
           <ColumnDefinition Width="*"/>
           <ColumnDefinition Width="*"/>
         </Grid.ColumnDefinitions>
         ...     
       </Grid>
       <Grid Grid.Row="1">
         <Grid.ColumnDefinitions>
           <ColumnDefinition Width="*"/>
         </Grid.ColumnDefinitions>
         <Grid.RowDefinitions>
           <RowDefinition Height="*"/>
         </Grid.RowDefinitions>
         <WebView x:Name="webw1" Grid.Row="0" Grid.Column="0"></WebView>
       </Grid>
       <Grid Grid.Row="2" >
         <Grid.RowDefinitions>
           <RowDefinition/>
         </Grid.RowDefinitions>
         <Grid.ColumnDefinitions>
           <ColumnDefinition Width="*"/>
         </Grid.ColumnDefinitions>
         <ScrollView Grid.Row="0" Grid.Column="0">
           <Label Text="LastExplanation" x:Name="lblLastExplanation" />
         </ScrollView>
       </Grid>
     </Grid>
   </Grid>
 </ContentPage>

public FinalCheck()
{
  InitializeComponent();
  webw1.Source = DependencyService.Get<IBaseUrl>().Get() + "instruction.html";
}

你可以在加载事件中注入一个返回HTML内容高度的JavaScript函数,然后使用获取到的高度设置你的Web视图的高度。 - Sparsha Bhattarai
1个回答

0

如果不需要更改,最简单的方法是:

<WebView x:Name="webw1" Grid.Row="0" Grid.Column="0" HeightRequest="xxx"></WebView>

或者

你可以创建一个自定义渲染器或者创建一种与你的HTML页面通信并发送数据(在这种情况下为高度)的方式。

此链接 可能会在高度需要动态/交互性时有所帮助。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接