简体   繁体   English

Xamarin.Forms 帧内容在Android中溢出

[英]Xamarin.Forms Frame content flowing out of bounds in Android

I have a Xamarin.Forms app (4.6.0.800) & I'm making a control using Frame for the rounded corners.我有一个 Xamarin.Forms 应用程序(4.6.0.800)&我正在使用 Frame 进行圆角控制。 But the background color of grid flows out of the bounds of the frame on Android.但是网格的背景颜色在 Android 上超出了框架的范围。 It works as expected on iOS.它在 iOS 上按预期工作。

在此处输入图像描述

Here's the XAML code这是 XAML 代码

<Frame x:Name="MainFrame" CornerRadius="8" Padding="1" BorderColor="Black" HorizontalOptions="FillAndExpand"
               IsClippedToBounds="True">

            <Grid HorizontalOptions="FillAndExpand">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition></ColumnDefinition>
                    <ColumnDefinition></ColumnDefinition>
                </Grid.ColumnDefinitions>
                <Grid x:Name="FirstButton" Grid.Column="0">
                    <Grid.GestureRecognizers>
                        <TapGestureRecognizer Tapped="FirstButton_Tapped" />
                    </Grid.GestureRecognizers>
                    <controls:ShapeView x:Name="FirstBox" 
                                        CornerRadius="8" Margin="0,0,-4,0"
                                        ShapeType="Box"
                                        HorizontalOptions="FillAndExpand" VerticalOptions="Center"/>
                    <Label x:Name="FirstBoxLabel"
                       VerticalOptions="Center" HorizontalOptions="Center"/>
                </Grid>
                <Grid x:Name="SecondButton" Grid.Column="1" >
                    <Grid.GestureRecognizers>
                        <TapGestureRecognizer Tapped="SecondButton_Tapped" />
                    </Grid.GestureRecognizers>
                    <controls:ShapeView x:Name="SecondBox"
                                        CornerRadius="8" Margin="-4,0,0,0"
                                        ShapeType="Box"
                                        HorizontalOptions="FillAndExpand" VerticalOptions="Center"/>
                    <Label x:Name="SecondBoxLabel" 
                       VerticalOptions="Center" HorizontalOptions="Center"/>
                </Grid>
            </Grid>
        </Frame>

I have tried adding IsClippedToBounds="True" but that didn't help either.我尝试添加IsClippedToBounds="True"但这也无济于事。 I wonder what am I missing?我想知道我错过了什么?

It seems an existing issue on some version of Xamarin.Forms when we set the BorderColor .当我们设置BorderColor时,Xamarin.Forms 的某些版本似乎存在问题。 As as workaround, you could add an extra Frame as the parent layout of the CusTomView.作为解决方法,您可以添加一个额外的 Frame 作为 CusTomView 的父布局。 In this way you don't need to set BorderColor any more.这样就不需要再设置BorderColor了。 Check the following code.检查以下代码。

// padding here will become the bordercolor of the frame
<Frame BackgroundColor="Black" Padding="1" CornerRadius="8">
            <Frame x:Name="MainFrame" CornerRadius="8" Padding="0"  HorizontalOptions="FillAndExpand"
               IsClippedToBounds="True" >
                <Grid HorizontalOptions="FillAndExpand">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition></ColumnDefinition>
                        <ColumnDefinition></ColumnDefinition>
                    </Grid.ColumnDefinitions>
                    <Grid x:Name="FirstButton" Grid.Column="0">
                        <Grid.GestureRecognizers>
                            <TapGestureRecognizer Tapped="FirstButton_Tapped" />
                        </Grid.GestureRecognizers>
                        <BoxView x:Name="FirstBox" 
                                        CornerRadius="8" Margin="0,0,-4,0"
                                        HorizontalOptions="FillAndExpand" VerticalOptions="Center"/>
                        <Label x:Name="FirstBoxLabel"
                       VerticalOptions="Center" HorizontalOptions="Center"/>
                    </Grid>
                    <Grid x:Name="SecondButton" Grid.Column="1" >
                        <Grid.GestureRecognizers>
                            <TapGestureRecognizer Tapped="SecondButton_Tapped" />
                        </Grid.GestureRecognizers>
                        <BoxView x:Name="SecondBox"
                                        CornerRadius="8" Margin="-4,0,0,0"
                                        HorizontalOptions="FillAndExpand" VerticalOptions="Center"/>
                        <Label x:Name="SecondBoxLabel" 
                       VerticalOptions="Center" HorizontalOptions="Center"/>
                    </Grid>
                </Grid>
            </Frame>
        </Frame>

在此处输入图像描述

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

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