Xamarin Forms 4.1:ScrollView 滚动覆盖 android 设备 9.0 中的 header 视图
Xamarin Forms 4.1: ScrollView scroll is covering header view in android device 9.0
在 Xamarin Forms 4.1 中,滚动时,scrollview 内容是covering/overflowheaderview 和 scrollview 内容没有完全显示。
尝试 IsClippedToBounds 为真。
创建了 scrollviewrenderer,OnDraw() -> 将剪辑设置为绑定 属性。但是没用。
示例:这是 XAML 设计
<Stacklayout>
<HeaderView/>
<ScrollView IsClippedToBounds="true">
<Stacklayout>
<label text="1"/>
........
........
<label text="100"/>
</Stacklayout>
</ScrollView>
</Stacklayout>
如果您希望您的 header 始终可见,而不是将您的内容放在 Header 中,最好先放置您的 header 内容,然后再放在您的内容下方列表显示。因此,您的 header 保持不变并且列表视图滚动。
我在你的描述中制作了一个自定义控件作为headerview。并在 Xamarin.forms 4.1 上测试,效果很好。
MyCustomConrol:
<StackLayout Orientation="Horizontal" BackgroundColor="Aqua">
<Label x:Name="Title_label" Text="Title" TextColor="Black" FontSize="25" HorizontalOptions="StartAndExpand" Margin="8,0,4,0"/>
<Button x:Name="btnHello" Text="Hello" HorizontalOptions="EndAndExpand" Margin="4,0,8,0"/>
</StackLayout>
MainPage.xaml
<StackLayout>
<local:MyCustomControl></local:MyCustomControl>
<!--<HeaderView/>-->
<ScrollView IsClippedToBounds="true">
<StackLayout>
<Label Text="1"/>
<Label Text="2"/>
<Label Text="3"/>
……………
…………………
</StackLayout>
</ScrollView>
结果:
您可以从 GitHub 的 ScrollView/XamarinDemo 文件夹下载以供参考。
https://github.com/WendyZang/Test.git
在 Xamarin Forms 4.1 中,滚动时,scrollview 内容是covering/overflowheaderview 和 scrollview 内容没有完全显示。
尝试 IsClippedToBounds 为真。 创建了 scrollviewrenderer,OnDraw() -> 将剪辑设置为绑定 属性。但是没用。
示例:这是 XAML 设计
<Stacklayout>
<HeaderView/>
<ScrollView IsClippedToBounds="true">
<Stacklayout>
<label text="1"/>
........
........
<label text="100"/>
</Stacklayout>
</ScrollView>
</Stacklayout>
如果您希望您的 header 始终可见,而不是将您的内容放在 Header 中,最好先放置您的 header 内容,然后再放在您的内容下方列表显示。因此,您的 header 保持不变并且列表视图滚动。
我在你的描述中制作了一个自定义控件作为headerview。并在 Xamarin.forms 4.1 上测试,效果很好。
MyCustomConrol:
<StackLayout Orientation="Horizontal" BackgroundColor="Aqua">
<Label x:Name="Title_label" Text="Title" TextColor="Black" FontSize="25" HorizontalOptions="StartAndExpand" Margin="8,0,4,0"/>
<Button x:Name="btnHello" Text="Hello" HorizontalOptions="EndAndExpand" Margin="4,0,8,0"/>
</StackLayout>
MainPage.xaml
<StackLayout>
<local:MyCustomControl></local:MyCustomControl>
<!--<HeaderView/>-->
<ScrollView IsClippedToBounds="true">
<StackLayout>
<Label Text="1"/>
<Label Text="2"/>
<Label Text="3"/>
……………
…………………
</StackLayout>
</ScrollView>
结果:
您可以从 GitHub 的 ScrollView/XamarinDemo 文件夹下载以供参考。 https://github.com/WendyZang/Test.git