如何在整个自上而下的屏幕上制作列表视图

时间:2019-10-27 16:45:03

标签: c# xaml xamarin xamarin.forms

我在一个页面中有两个ListView,我希望它们以这样一种方式显示:只有一次,我将第一个向下滚动到按钮,然后第二个向下滚动。我该怎么办?

到目前为止,我能够同时显示两个ListView,但是它们将屏幕分成了两个,分别是顶部的第一个列表视图和按钮上的第二个列表视图(请参见下面的屏幕截图!)

enter image description here

我要实现的目标类似于以下链接中的图片:

https://cdn.dribbble.com/users/2568324/screenshots/6893977/dribbble8.png

我的代码如下:

    <Frame>
        <ListView x:Name = "MainMagazine" RowHeight="200" ItemSelected="MainMagazine_se" VerticalOptions="StartAndExpand">
            <ListView.ItemTemplate>
                <DataTemplate >
                    <ViewCell>
                        <StackLayout>

                            <Image Source = "{Binding Urlimage}" WidthRequest = "400" Margin="0,-200" HeightRequest = "500" MinimumHeightRequest = "500" MinimumWidthRequest = "400" />

                            <StackLayout Margin="0,45" >
                                <Label Text = "{Binding Title}" FontSize = "15" TextColor = "Black"/>
                                <Label Text = "{Binding MiniContent}" FontSize = "12" TextColor = "Gray" Margin="0,-7"/>
                            </StackLayout>

                        </StackLayout>
                    </ViewCell>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
    </Frame>

    <Frame>
        <ListView x:Name = "MainMagazine2" RowHeight="200" ItemSelected="MainMagazine_se" VerticalOptions="Center" >
            <ListView.ItemTemplate>
                <DataTemplate >
                    <ViewCell>
                        <StackLayout Padding="0,0,0,300">

                            <Image Source = "{Binding Urlimage}" WidthRequest = "400" Margin="0,-200" HeightRequest = "500" MinimumHeightRequest = "500" MinimumWidthRequest = "400" />

                            <StackLayout Margin="0,45" >
                                <Label Text = "{Binding Title}" FontSize = "15" TextColor = "Black"/>
                                <Label Text = "{Binding MiniContent}" FontSize = "12" TextColor = "Gray" Margin="0,-7"/>
                            </StackLayout>

                        </StackLayout>
                    </ViewCell>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
    </Frame>

1 个答案:

答案 0 :(得分:-1)

如果您要设置两个 ListView ,一个在另一个之上,以便您可以向下滚动到一个按钮,然后看到第二个并继续滚动该按钮,可以将您的两个 ListView 都放在ScrollView中:

您的视图应类似于:

<ScrollView>
    <StackLayout>
            <Frame>
                ...
            </Frame>

            <Frame>
                ...
            </Frame>
    </StackLayout>
</ScrollView>