调整网格行中的框架大小

时间:2019-11-27 05:53:26

标签: xamarin mobile

我将xamarin与用于iOS和Android的Visual Studio一起使用

我正在尝试将scrollView添加到“框架”所在的同一网格行中,但是由于该框架与我的网格行的大小相同,因此会切掉框架的底部(我相信)

我尝试过的方法: 1.将RowDefinition设置为“ *”和“ Auto”,但是框架随着网格和 2.调整scrollView高度

我觉得最好的选择是调整框架的大小,使其小于网格行,但是heightRequest无效。.我很乐意提供任何建议。

代码如下:

components

1 个答案:

答案 0 :(得分:1)

<StackLayout Orientation="Horizontal" Grid.Row="4" BackgroundColor="Red">

定义了 StackLayout Orientaition="Horizontal"后,框架将默认填充高度。

如果要调整框架高度,则应设置其 VerticalOptions 属性

喜欢:

<ScrollView Orientation="Horizontal" Grid.Row="4"  Margin="0,20,0,0"  HorizontalScrollBarVisibility="Never">
                <StackLayout Orientation="Horizontal"  BackgroundColor="Red" >
                    <Frame  VerticalOptions="CenterAndExpand" HeightRequest="270" WidthRequest="200" Padding="0,0,0,0" CornerRadius="10" IsClippedToBounds="True" Margin="15,0,0,0">
                        <StackLayout>
                            <Image Source="satayChicken.jpg" WidthRequest="200" HeightRequest="200" Aspect="AspectFill"></Image>
                            <Label Text="Satay Chicken" FontSize="24" TextColor="#48b67b"  HorizontalOptions="Center" Margin="0,-5,0,0"/>
                            <StackLayout Orientation="Horizontal" HorizontalOptions="Center">
                                <Label Text="PREP TIME" FontSize="12" TextColor="#4a6356" />
                                <Label Text="COOK TIME" FontSize="12" TextColor="#4a6356" Margin="5,0,0,0"/>
                            </StackLayout>
                            <StackLayout Orientation="Horizontal" HorizontalOptions="Center" Margin="0,-10,0,0">
                                <Label Text="5 mins" FontSize="14" TextColor="#48b67b" />
                                <Label Text="12 mins" FontSize="14" TextColor="#48b67b" Margin="15,0,0,0"/>
                            </StackLayout>
                        </StackLayout>
                    </Frame>

                </StackLayout>
</ScrollView>

具体尺寸是根据您的要求设置的。

或者您也可以将Padding属性设置为StackLayout以调整Frame位置的大小,例如:

<StackLayout Padding="0,10,0,10" Orientation="Horizontal" Grid.Row="4" BackgroundColor="Red">
                    <Frame WidthRequest="200" HeightRequest="300" Padding="0,0,0,0" CornerRadius="10" IsClippedToBounds="True" Margin="15,0,0,0">
                        <StackLayout>
                            <Image Source="satayChicken.jpg" WidthRequest="200" HeightRequest="200" Aspect="AspectFill"></Image>
                            <Label Text="Satay Chicken" FontSize="24" TextColor="#48b67b"  HorizontalOptions="Center" Margin="0,-5,0,0"/>
                            <StackLayout Orientation="Horizontal" HorizontalOptions="Center">
                                <Label Text="PREP TIME" FontSize="12" TextColor="#4a6356" />
                                <Label Text="COOK TIME" FontSize="12" TextColor="#4a6356" Margin="5,0,0,0"/>
                            </StackLayout>
                            <StackLayout Orientation="Horizontal" HorizontalOptions="Center" Margin="0,-10,0,0">
                                <Label Text="5 mins" FontSize="14" TextColor="#48b67b" />
                                <Label Text="12 mins" FontSize="14" TextColor="#48b67b" Margin="15,0,0,0"/>
                            </StackLayout>
                        </StackLayout>
                    </Frame>

 </StackLayout>