【问题标题】:How to make listview all over the top-down screen如何在自上而下的屏幕上制作列表视图
【发布时间】:2019-10-28 17:33:32
【问题描述】:

我在一个页面中有两个 ListView,我希望它们以这样一种方式显示,即只要我将第一个向下滚动到按钮,第二个就会跟随。我该怎么做?

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

我想要实现的就像下面链接中的图片:

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>

【问题讨论】:

  • 使用 2 行的网格,每行 50%。然后在每一行放置一个ListView
  • Jason,你能告诉我怎么做吗?
  • 你能告诉我们你到底想达到什么目标吗?
  • 如果您在顶部看到新图像,您可以在中心看到两个列表剪切。我不想要那个,我想要两个列表,但不要在屏幕上剪切,就像 link
  • 所以你希望能够将第一个向下滚动到最后,然后第二个列表视图应该出现?

标签: c# xaml xamarin xamarin.forms


【解决方案1】:

如果你想设置两个ListView,一个在另一个之上,这样你可以向下滚动一个到按钮,然后看到第二个并继续滚动那个,你可以将您的两个 ListView 放入 ScrollView:

你的视图应该是这样的:

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

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

【讨论】:

  • 你永远不应该在 ScrollView 中嵌套 ListView。非常糟糕的做法! ListView 实现自己的滚动。 ListView 不会接收任何手势,因为它们将由父 ScrollView 处理。 ListView 可以呈现随列表元素滚动的自定义页眉和页脚,从而可能提供 ScrollView 用于的功能。
  • 感谢@TaiT 的评论,但没有人要求最佳实践。 OP有一个问题,我的回答解决了这个问题......这就是它的工作原理......如果你有更好的(类似最佳实践的)方法来解决OP中所述的问题,请随时发布。我也有兴趣从中学习。
猜你喜欢
  • 1970-01-01
  • 2015-05-29
  • 1970-01-01
  • 2013-11-08
  • 2010-10-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多