简体   繁体   English

Xamarin Forms 中另一个 ScrollView 中的 ScrollView

[英]ScrollView Inside another ScrollView in Xamarin Forms

I am developing an app, using Xamarin Forms.我正在使用 Xamarin Forms 开发应用程序。 In this App I want the user to be able to scroll The entire Page Vertically, but only a part of the page vertically.在这个应用程序中,我希望用户能够垂直滚动整个页面,但只能垂直滚动页面的一部分。 See this image for a visual reference.请参阅此图像以获取视觉参考。 I read on the Xamarin ScrollView Documentation, that我在 Xamarin ScrollView Documentation 上读到,

ScrollView objects should not be nested.不应嵌套 ScrollView 对象。 In addition, ScrollView objects should not be nested with other controls that provide scrolling, such as CollectionView, ListView, and WebView.此外,ScrollView 对象不应与其他提供滚动的控件嵌套,例如 CollectionView、ListView 和 WebView。

So, how can I achieve this without nesting two ScrollViews?那么,如何在不嵌套两个 ScrollView 的情况下实现这一点? Thanks in advance for your help.在此先感谢您的帮助。

It's possible to have 2 nested scroll viewers in Xamarin.Forms. Xamarin.Forms 中可以有 2 个嵌套的滚动查看器。

Notice how it says 'scroll viewers should not be nested, this means that it is certainly possible but it is not recommended.请注意它如何说“不应嵌套滚动查看器”,这意味着这当然是可能的,但不建议这样做。 I think nested scroll viewers creates a bad user-experience and makes for a clunky app, especially for Xamarin.Forms;我认为嵌套滚动查看器会带来糟糕的用户体验,并且会导致应用程序笨拙,尤其是对于 Xamarin.Forms; but again, here is a demonstration of a nested scroll viewer:但同样,这是嵌套滚动查看器的演示:

 <ScrollView Orientation="Horizontal">
        <StackLayout Orientation="Vertical">
            <Grid>
            </Grid>
            <ScrollView Orientation="Vertical">
                <Grid>
                </Grid>
            </ScrollView>
        </StackLayout>
    </ScrollView>

I think once you've played around with nested scroll viewers it should be easy for you to implement what you want.我认为一旦你玩过嵌套滚动查看器,你应该很容易实现你想要的。 I would recommend using a grid with column and row definitions with your desired measurements.我建议使用带有列和行定义的网格以及您想要的测量值。

If I've answered your question, please mark this as the correct answer.如果我已经回答了您的问题,请将其标记为正确答案。

Thanks,谢谢,

According to your screenshot, i make a code sample for your reference.根据您的截图,我制作了一个代码示例供您参考。

Xaml: Xml:

 <ScrollView Orientation="Vertical">
    <StackLayout Orientation="Horizontal">
        <BoxView BackgroundColor="Blue" WidthRequest="150" />
        <StackLayout Orientation="Vertical">
            <ScrollView Orientation="Horizontal" BackgroundColor="Accent">
                <StackLayout Orientation="Horizontal">
                    <Label
                        HeightRequest="50"
                        Text="A1"
                        WidthRequest="50" />
                    <Label
                        HeightRequest="50"
                        Text="A2"
                        WidthRequest="50" />
                    <Label
                        HeightRequest="50"
                        Text="A3"
                        WidthRequest="50" />
                    <Label
                        HeightRequest="50"
                        Text="A4"
                        WidthRequest="50" />
                    <Label
                        HeightRequest="50"
                        Text="A5"
                        WidthRequest="50" />
                    <Label
                        HeightRequest="50"
                        Text="A6"
                        WidthRequest="50" />
                    <Label
                        HeightRequest="50"
                        Text="A7"
                        WidthRequest="50" />
                    <Label
                        HeightRequest="50"
                        Text="A8"
                        WidthRequest="50" />
                    <Label
                        HeightRequest="50"
                        Text="A9"
                        WidthRequest="50" />
                    <Label
                        HeightRequest="50"
                        Text="A10"
                        WidthRequest="50" />
                </StackLayout>
            </ScrollView>
            <Label HeightRequest="150" Text="Elem1"  BackgroundColor="Green"/>
            <Label HeightRequest="150" Text="Elem2"  BackgroundColor="Green"/>
            <Label HeightRequest="150" Text="Elem3"  BackgroundColor="Green"/>
            <Label HeightRequest="150" Text="Elem4"  BackgroundColor="Green"/>
            <Label HeightRequest="150" Text="Elem5"  BackgroundColor="Green"/>
            <ScrollView Orientation="Horizontal">
                <StackLayout Orientation="Horizontal">
                    <Label
                        HeightRequest="50"
                        Text="B1"
                        WidthRequest="50" />
                    <Label
                        HeightRequest="50"
                        Text="B2"
                        WidthRequest="50" />
                    <Label
                        HeightRequest="50"
                        Text="B3"
                        WidthRequest="50" />
                    <Label
                        HeightRequest="50"
                        Text="B4"
                        WidthRequest="50" />
                    <Label
                        HeightRequest="50"
                        Text="B5"
                        WidthRequest="50" />
                    <Label
                        HeightRequest="50"
                        Text="B6"
                        WidthRequest="50" />
                    <Label
                        HeightRequest="50"
                        Text="B7"
                        WidthRequest="50" />
                    <Label
                        HeightRequest="50"
                        Text="B8"
                        WidthRequest="50" />
                    <Label
                        HeightRequest="50"
                        Text="B9"
                        WidthRequest="50" />
                    <Label
                        HeightRequest="50"
                        Text="B10"
                        WidthRequest="50" />
                </StackLayout>
            </ScrollView>
        </StackLayout>
    </StackLayout>

</ScrollView>

Screenshot:截屏:

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM