Maui ImageButton 与 FontImageSource - 如何调整图像大小? .net 8

问题描述 投票:0回答:1

我刚刚将我的 maui android/ios 项目更新到 .net 8,我的 ImageButtons 现在呈现不同的效果。

在 .net 7 中,我没有设置 ImageButton 的高度/宽度,按钮的大小将根据填充进行调整。我找到了一个我喜欢的平衡,图像显示时带有一些填充,这样它就不会被圆角半径切断。

在 .net 8 中,我需要设置高度/宽度才能显示 ImageButton。然而,设置 ImageButton 高度/宽度尺寸后,填充值没有任何区别(这与 .net 7 中的行为相同)。

由于某种原因,FontImageSource 现在渲染得比以前更大,并且填充没有任何区别,我无法让图像很好地适应按钮而不被角半径切断。 FontImageSource 图标没有改变。

我尝试了各种不同的高度/宽度、填充和角半径,以及设置 fontImageSource 的大小,但我无法复制 .net 7 中此按钮的外观!

我想让它看起来像上图中顶部中间的图标。有谁知道需要更改什么才能使图标正确显示?

<Grid Margin="0" BackgroundColor="Black" >
    <Grid.RowDefinitions>
        <RowDefinition Height="40" />
        <RowDefinition Height="*" />
    </Grid.RowDefinitions>

    <ImageButton Grid.Row="1" Margin="15,0,15,10" 
        HorizontalOptions="End" 
        VerticalOptions="End" 
        HeightRequest="40" 
        WidthRequest="40"
        Padding="5"
        CornerRadius="20"
        BackgroundColor="#32578f">
        <ImageButton.Source>
            <FontImageSource  
                Glyph="{x:Static m:MaterialOutlined.Grid_view}" 
                FontFamily="MaterialOutlined" 
                Color="White" 
                Size="10"/>
        </ImageButton.Source>
    </ImageButton>
</Gird>

        
maui imagebutton .net-8.0 maui-android
1个回答
0
投票

尝试使用

Scale
,并删除填充。

<Grid Margin="0" BackgroundColor="Black" >
    <Grid.RowDefinitions>
        <RowDefinition Height="40" />
        <RowDefinition Height="*" />
    </Grid.RowDefinitions>

    <ImageButton Grid.Row="1" Margin="15,0,15,10" 
        HorizontalOptions="End" 
        VerticalOptions="End" 
        HeightRequest="40" 
        WidthRequest="40"
        Scale="0.5"
        CornerRadius="20"
        BackgroundColor="#32578f">
        <ImageButton.Source>
            <FontImageSource  
                Glyph="{x:Static m:MaterialOutlined.Grid_view}" 
                FontFamily="MaterialOutlined" 
                Color="White" 
                Size="10"/>
        </ImageButton.Source>
    </ImageButton>
</Gird>
© www.soinside.com 2019 - 2024. All rights reserved.