垂直滚动视图在 xamarin 表单中不起作用。?

Vertiical Scrollview not working in xamarin forms.?

我正在尝试在 Xamarin Forms 中滚动 xfxCardview。但它不是滚动的。这是我的代码

            <ScrollView  Orientation = "Vertical" VerticalOptions="FillAndExpand">
                <StackLayout Orientation="Vertical" VerticalOptions="FillAndExpand">
            <xfx:XfxCardView 
                    BackgroundColor="White"
                    CornerRadius="30" 
                Elevation="20"
             HeightRequest="160" IsClippedToBounds="True" VerticalOptions="FillAndExpand">
                <StackLayout Orientation="Horizontal">

                    <Grid VerticalOptions="CenterAndExpand"  
             Padding="0"  
             HorizontalOptions="FillAndExpand"  
             BackgroundColor="Transparent">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="25" />
                            <RowDefinition Height="25" />
                            <RowDefinition Height="25" />
                            <RowDefinition Height="35" />
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="100"/>
                            <ColumnDefinition Width="*"/>
                            <ColumnDefinition Width="*"/>
                            <ColumnDefinition Width="*"/>
                            <ColumnDefinition Width="*"/>
                            <ColumnDefinition Width="*"/>
                            <ColumnDefinition Width="*"/>
                        </Grid.ColumnDefinitions>
                        <Frame Margin="10,5,5,-20"  CornerRadius="10" Grid.RowSpan="3"  BackgroundColor="LightBlue"  IsClippedToBounds="True">
                            <Image Margin="-70,-70,-70,-70"  Grid.Row="0" Grid.Column="0" Grid.RowSpan="4" Source="restaurantimage1.jpg" />
                        </Frame>
                        <Label Grid.Row="0" Grid.Column="1" Grid.ColumnSpan="4" Margin="0,10,0,0"  TextColor="Black" FontFamily="Bold,100"  Text="Premera restaurant" />
                        <Image Grid.Row="0" Grid.Column="5" Margin="0,10,0,0"  Source="whitehearticon3"/>
                        <Label Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="6" Text="Avenue Road, 256" TextColor="Blue" />
                        <Label Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="6" Text="Indian,Italy,Chinese Kitchen" />
                        <Image Grid.Row="3" Grid.Column="1"   Source="whitestaricon1"/>
                        <Label Grid.Row="3" Grid.Column="2" HeightRequest="30" Text="4,3" />
                        <Image Grid.Row="3" Grid.Column="3" Margin="-10,0,0,0"   Source="rupeeicon1"/>
                        <Label Grid.Row="3" Grid.Column="4"  Margin="-10,0,0,0" Text="150 min" />
                        <Image Grid.Row="3" Grid.Column="5" Margin="-20,0,0,0"  Source="handicon1"/>
                            <Label Grid.Row="3" Grid.Column="6"  Margin="-10,0,0,0" HeightRequest="10" Text="Free 3kms" />
                    </Grid>
                </StackLayout>
            </xfx:XfxCardView>

                <xfx:XfxCardView 
                    BackgroundColor="White"
                    CornerRadius="30" 
                Elevation="20"
             HeightRequest="160" IsClippedToBounds="True" VerticalOptions="FillAndExpand">
                <StackLayout Orientation="Horizontal">

                    <Grid VerticalOptions="CenterAndExpand"  
             Padding="0"  
             HorizontalOptions="FillAndExpand"  
             BackgroundColor="Transparent">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="35" />
                            <RowDefinition Height="25" />
                            <RowDefinition Height="25" />
                            <RowDefinition Height="35" />
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="100"/>
                            <ColumnDefinition Width="*"/>
                            <ColumnDefinition Width="*"/>
                            <ColumnDefinition Width="*"/>
                            <ColumnDefinition Width="*"/>
                            <ColumnDefinition Width="*"/>
                            <ColumnDefinition Width="*"/>
                        </Grid.ColumnDefinitions>
                        <Frame Margin="10,5,5,-20"  CornerRadius="10" Grid.RowSpan="3"  BackgroundColor="LightBlue"  IsClippedToBounds="True">
                            <Image Margin="-70,-70,-70,-70"  Grid.Row="0" Grid.Column="0" Grid.RowSpan="4" Source="restaurantimage2.jpg" />
                        </Frame>
                        <Label Grid.Row="0" Grid.Column="1" Grid.ColumnSpan="4" Margin="0,10,0,0"  TextColor="Black" FontFamily="Bold,100"  Text="Pesto restaurant" />
                        <Image Grid.Row="0" Grid.Column="5" Margin="0,10,0,0"   Source="whitehearticon3"/>
                        <Label Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="6"  Text="Bodhami Road, 6" TextColor="Blue"  />
                        <Label Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="6"  Text="Indian,Italy,Chinese Kitchen" />
                        <Image Grid.Row="3" Grid.Column="1"   Source="whitestaricon1"/>
                        <Label Grid.Row="3" Grid.Column="2" HeightRequest="30" Text="3,0" />

                        <Label Grid.Row="3" Grid.Column="4"  Grid.ColumnSpan="3"  Text="No available" TextColor="Blue" />
                    </Grid>
                </StackLayout>
            </xfx:XfxCardView>
                    <Label Text="RESTAURANTS AWAY FROM YOU" TextColor="#595959" HeightRequest="30"></Label>
                    <Label  Text="25 Restaurants finded" TextColor="#d9d9d9" HeightRequest="20"></Label>
                    <xfx:XfxCardView 
                    BackgroundColor="White"
                    CornerRadius="30" 
                Elevation="20"
             HeightRequest="160" IsClippedToBounds="True" VerticalOptions="FillAndExpand">
                        <StackLayout Orientation="Horizontal">

                            <Grid VerticalOptions="CenterAndExpand"  
             Padding="0"  
             HorizontalOptions="FillAndExpand"  
             BackgroundColor="Transparent">
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="25" />
                                    <RowDefinition Height="25" />
                                    <RowDefinition Height="25" />
                                    <RowDefinition Height="35" />
                                </Grid.RowDefinitions>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="100"/>
                                    <ColumnDefinition Width="*"/>
                                    <ColumnDefinition Width="*"/>
                                    <ColumnDefinition Width="*"/>
                                    <ColumnDefinition Width="*"/>
                                    <ColumnDefinition Width="*"/>
                                    <ColumnDefinition Width="*"/>
                                </Grid.ColumnDefinitions>
                                <Frame Margin="10,5,5,-20"  CornerRadius="10" Grid.RowSpan="3"  BackgroundColor="LightBlue"  IsClippedToBounds="True">
                                    <Image Margin="-70,-70,-70,-70"  Grid.Row="0" Grid.Column="0" Grid.RowSpan="4" Source="restaurantimage3.jpg" />
                                </Frame>
                                <Label Grid.Row="0" Grid.Column="1" Grid.ColumnSpan="4" Margin="0,10,0,0"  TextColor="Black" FontFamily="Bold,100"  Text="Hero" />
                                <Image Grid.Row="0" Grid.Column="5" Margin="0,10,0,0"  Source="whitehearticon3"/>
                                <Label Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="6" Text="Line street,2" TextColor="Blue" />
                                <Label Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="6" Text="Indian,Italy,Chinese Kitchen" />
                                <Image Grid.Row="3" Grid.Column="1"   Source="whitestaricon1"/>
                                <Label Grid.Row="3" Grid.Column="2" HeightRequest="30" Text="4,3" />
                                <Image Grid.Row="3" Grid.Column="3" Margin="-10,0,0,0"   Source="rupeeicon1"/>
                                <Label Grid.Row="3" Grid.Column="4"  Margin="-10,0,0,0" Text="150 min" />
                                <Image Grid.Row="3" Grid.Column="5" Margin="-20,0,0,0"  Source="handicon1"/>
                                <Label Grid.Row="3" Grid.Column="6"  Margin="-10,0,0,0" HeightRequest="10" Text="Free 3kms" />
                            </Grid>
                        </StackLayout>
                    </xfx:XfxCardView>

                </StackLayout>
            </ScrollView>

我不知道我的代码有什么问题我将方向设置为垂直我还将 VerticalOptions 设置为填充和展开。滚动视图是否有效,或者我应该将 XfxCardview 放在 Listview 中。这是我当前的 UI 的样子

并且 UI 不会滚动到底部。

您的 xaml 看起来不错,请尝试检查几项:

  1. 您没有忘记在 android 项目

  2. 中禁用滚动的滚动视图的自定义渲染器
  3. 检查它是否在没有设置高度的情况下滚动,可能是一个错误

  4. 另一个"bug"我可以想象:看看最后一张卡片:它可能只是没有达到它的160高度而只是用VerticalOptions="FillAndExpand"填充父级所以没有什么可滚动的。并且卡片的内容被 IsClippedToBounds="True" 裁剪,所以它没有 Expand 卡片。

在Android中,是卡片高度的问题。三个卡片视图与屏幕完美对齐。这就是您在 Android 中看不到滚动视图的原因。仅当滚动视图中的内容大于滚动视图高度时,滚动视图功能才可用。要解决此问题,请尝试以下解决方案。添加更多卡片视图,您将看到滚动视图。另一个解决方案是,我将高度添加为 300 到滚动视图。您可以根据自己的需求进行测试和修改。

  <ScrollView HeightRequest="300"  Orientation = "Vertical" VerticalOptions="FillAndExpand">
            <StackLayout Orientation="Vertical" VerticalOptions="FillAndExpand">
        <xfx:XfxCardView 
                BackgroundColor="White"
                CornerRadius="30" 
            Elevation="20"
         HeightRequest="260" IsClippedToBounds="True" VerticalOptions="FillAndExpand">
            <StackLayout Orientation="Horizontal">

                <Grid VerticalOptions="CenterAndExpand"  
         Padding="0"  
         HorizontalOptions="FillAndExpand"  
         BackgroundColor="Transparent">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="25" />
                        <RowDefinition Height="25" />
                        <RowDefinition Height="25" />
                        <RowDefinition Height="35" />
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="100"/>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="*"/>
                    </Grid.ColumnDefinitions>
                    <Frame Margin="10,5,5,-20"  CornerRadius="10" Grid.RowSpan="3"  BackgroundColor="LightBlue"  IsClippedToBounds="True">
                        <Image Margin="-70,-70,-70,-70"  Grid.Row="0" Grid.Column="0" Grid.RowSpan="4" Source="restaurantimage1.jpg" />
                    </Frame>
                    <Label Grid.Row="0" Grid.Column="1" Grid.ColumnSpan="4" Margin="0,10,0,0"  TextColor="Black" FontFamily="Bold,100"  Text="Premera restaurant" />
                    <Image Grid.Row="0" Grid.Column="5" Margin="0,10,0,0"  Source="whitehearticon3"/>
                    <Label Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="6" Text="Avenue Road, 256" TextColor="Blue" />
                    <Label Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="6" Text="Indian,Italy,Chinese Kitchen" />
                    <Image Grid.Row="3" Grid.Column="1"   Source="whitestaricon1"/>
                    <Label Grid.Row="3" Grid.Column="2" HeightRequest="30" Text="4,3" />
                    <Image Grid.Row="3" Grid.Column="3" Margin="-10,0,0,0"   Source="rupeeicon1"/>
                    <Label Grid.Row="3" Grid.Column="4"  Margin="-10,0,0,0" Text="150 min" />
                    <Image Grid.Row="3" Grid.Column="5" Margin="-20,0,0,0"  Source="handicon1"/>
                        <Label Grid.Row="3" Grid.Column="6"  Margin="-10,0,0,0" HeightRequest="10" Text="Free 3kms" />
                </Grid>
            </StackLayout>
        </xfx:XfxCardView>

            <xfx:XfxCardView 
                BackgroundColor="White"
                CornerRadius="30" 
            Elevation="20"
         HeightRequest="260" IsClippedToBounds="True" VerticalOptions="FillAndExpand">
            <StackLayout Orientation="Horizontal">

                <Grid VerticalOptions="CenterAndExpand"  
         Padding="0"  
         HorizontalOptions="FillAndExpand"  
         BackgroundColor="Transparent">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="25" />
                        <RowDefinition Height="25" />
                        <RowDefinition Height="25" />
                        <RowDefinition Height="35" />
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="100"/>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="*"/>
                    </Grid.ColumnDefinitions>
                    <Frame Margin="10,5,5,-20"  CornerRadius="10" Grid.RowSpan="3"  BackgroundColor="LightBlue"  IsClippedToBounds="True">
                        <Image Margin="-70,-70,-70,-70"  Grid.Row="0" Grid.Column="0" Grid.RowSpan="4" Source="restaurantimage2.jpg" />
                    </Frame>
                    <Label Grid.Row="0" Grid.Column="1" Grid.ColumnSpan="4" Margin="0,10,0,0"  TextColor="Black" FontFamily="Bold,100"  Text="Pesto restaurant" />
                    <Image Grid.Row="0" Grid.Column="5" Margin="0,10,0,0"   Source="whitehearticon3"/>
                    <Label Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="6"  Text="Bodhami Road, 6" TextColor="Blue"  />
                    <Label Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="6"  Text="Indian,Italy,Chinese Kitchen" />
                    <Image Grid.Row="3" Grid.Column="1"   Source="whitestaricon1"/>
                    <Label Grid.Row="3" Grid.Column="2" HeightRequest="30" Text="3,0" />

                    <Label Grid.Row="3" Grid.Column="4"  Grid.ColumnSpan="3"  Text="No available" TextColor="Blue" />
                </Grid>
            </StackLayout>
        </xfx:XfxCardView>
                <Label Text="RESTAURANTS AWAY FROM YOU" TextColor="#595959" HeightRequest="30"></Label>
                <Label  Text="25 Restaurants finded" TextColor="#d9d9d9" HeightRequest="20"></Label>
                <xfx:XfxCardView 
                BackgroundColor="White"
                CornerRadius="30" 
            Elevation="20"
         HeightRequest="260" IsClippedToBounds="True" VerticalOptions="FillAndExpand">
                    <StackLayout Orientation="Horizontal">

                        <Grid VerticalOptions="CenterAndExpand"  
         Padding="0"  
         HorizontalOptions="FillAndExpand"  
         BackgroundColor="Transparent">
                            <Grid.RowDefinitions>
                              <RowDefinition Height="25" />
                        <RowDefinition Height="25" />
                        <RowDefinition Height="25" />
                        <RowDefinition Height="35" />
                            </Grid.RowDefinitions>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="100"/>
                                <ColumnDefinition Width="*"/>
                                <ColumnDefinition Width="*"/>
                                <ColumnDefinition Width="*"/>
                                <ColumnDefinition Width="*"/>
                                <ColumnDefinition Width="*"/>
                                <ColumnDefinition Width="*"/>
                            </Grid.ColumnDefinitions>
                            <Frame Margin="10,5,5,-20"  CornerRadius="10" Grid.RowSpan="3"  BackgroundColor="LightBlue"  IsClippedToBounds="True">
                                <Image Margin="-70,-70,-70,-70"  Grid.Row="0" Grid.Column="0" Grid.RowSpan="4" Source="restaurantimage3.jpg" />
                            </Frame>
                            <Label Grid.Row="0" Grid.Column="1" Grid.ColumnSpan="4" Margin="0,10,0,0"  TextColor="Black" FontFamily="Bold,100"  Text="Hero" />
                            <Image Grid.Row="0" Grid.Column="5" Margin="0,10,0,0"  Source="whitehearticon3"/>
                            <Label Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="6" Text="Line street,2" TextColor="Blue" />
                            <Label Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="6" Text="Indian,Italy,Chinese Kitchen" />
                            <Image Grid.Row="3" Grid.Column="1"   Source="whitestaricon1"/>
                            <Label Grid.Row="3" Grid.Column="2" HeightRequest="30" Text="4,3" />
                            <Image Grid.Row="3" Grid.Column="3" Margin="-10,0,0,0"   Source="rupeeicon1"/>
                            <Label Grid.Row="3" Grid.Column="4"  Margin="-10,0,0,0" Text="150 min" />
                            <Image Grid.Row="3" Grid.Column="5" Margin="-20,0,0,0"  Source="handicon1"/>
                            <Label Grid.Row="3" Grid.Column="6"  Margin="-10,0,0,0" HeightRequest="10" Text="Free 3kms" />
                        </Grid>
                    </StackLayout>
                </xfx:XfxCardView>
            </StackLayout>
        </ScrollView>