【问题标题】:Xamarin CornerRadius behavior - Frame and ImageButtonXamarin CornerRadius 行为 - 框架和 ImageButton
【发布时间】:2020-03-29 12:06:23
【问题描述】:

我在使用 Xamarin.Forms 中的 CornerRadius 时遇到了一些问题。我想要一个具有 CornerRadius=100 的 ImageButton 和一个 Frame(其中包含一个图像)。 这在 Android 上运行良好,但在 iOS 上运行时无法按预期运行: Frame 不再是一个圆圈,并且 ImageButton 消失了。

Picture of iOS and Android Emulator

我的代码:

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:d="http://xamarin.com/schemas/2014/forms/design" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" x:Class="FrameTest.MainPage">
<Grid>
    <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <ImageButton Grid.Row="0" 
                     Grid.Column="0" 
                     BackgroundColor="#fc85ae" 
                     CornerRadius="100" 
                     Padding="2" 
                     Source="settings_wheel.png"
                     HeightRequest="40" 
                     WidthRequest="40"
                     HorizontalOptions="End"/>

        <Frame Grid.Row="1" 
               Grid.Column="0" 
               BorderColor="Black"
               CornerRadius="100"
               HeightRequest="100"
               WidthRequest="100"
               IsClippedToBounds="True"
               HorizontalOptions="Center"
               VerticalOptions="Center">
        <Image x:Name="ProfilePictureView"
               BackgroundColor="#fc85ae" />
        </Frame>
</Grid>

Xamarin.Essentials:1.3.1 Xamarin.Forms:4.3.0.908675

【问题讨论】:

    标签: c# xaml xamarin xamarin.forms


    【解决方案1】:

    是的,它适用于 Android,但不适用于 iOS。要在两个平台上实现圆形,您必须划分 HeightRequest / 2。这是您正确的 CornerRadius。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-04-09
      • 1970-01-01
      • 2019-08-23
      • 1970-01-01
      • 2011-10-24
      • 1970-01-01
      • 2018-10-24
      • 1970-01-01
      相关资源
      最近更新 更多