需要一种在 Xamarin 布局 XAML 中将 <ScrollView/> 放置在 <Image/> 上的方法
Need a way to place a <ScrollView/> over an <Image/> in Xamarin layout XAML
我需要在背景图片上添加一个滚动视图。我发现了一些使用 a 的建议,使图像成为第一个元素。我最终得到的是:
<ContentPage>
<ContentPage.Content>
<RelativeLayout Padding="0">
<Image Aspect="AspectFill" Source="Background" />
<ScrollView>
<!-- Various components -->
</ScrollView>
</RelativeLayout>
</ContentPage.Content>
</ContentPage>
使用上面的方法,我得到了一个看起来正确的屏幕,但 ScrollView 没有滚动。
我错过了什么吗?或者有人可以替代上面的布局吗?背景需要固定,不能与“顶部”的其他元素一起滚动。
事实证明有一种方法可以满足两个主要要求(固定背景、可滚动元素)。
不使用 RelativeLayout,而是使用 Grid。以下布局可根据需要使用...
<ContentPage>
<ContentPage.Content>
<!-- Use a Grid, rather than a RelativeLayout -->
<Grid Padding="0">
<Image Aspect="AspectFill" Source="Background" />
<ScrollView>
<!-- Various components -->
</ScrollView>
</Grid>
</ContentPage.Content>
</ContentPage>
我需要在背景图片上添加一个滚动视图。我发现了一些使用 a 的建议,使图像成为第一个元素。我最终得到的是:
<ContentPage>
<ContentPage.Content>
<RelativeLayout Padding="0">
<Image Aspect="AspectFill" Source="Background" />
<ScrollView>
<!-- Various components -->
</ScrollView>
</RelativeLayout>
</ContentPage.Content>
</ContentPage>
使用上面的方法,我得到了一个看起来正确的屏幕,但 ScrollView 没有滚动。
我错过了什么吗?或者有人可以替代上面的布局吗?背景需要固定,不能与“顶部”的其他元素一起滚动。
事实证明有一种方法可以满足两个主要要求(固定背景、可滚动元素)。
不使用 RelativeLayout,而是使用 Grid。以下布局可根据需要使用...
<ContentPage>
<ContentPage.Content>
<!-- Use a Grid, rather than a RelativeLayout -->
<Grid Padding="0">
<Image Aspect="AspectFill" Source="Background" />
<ScrollView>
<!-- Various components -->
</ScrollView>
</Grid>
</ContentPage.Content>
</ContentPage>