Xamarin.forms 图片不´;t安装图像按钮
我想用Xamarin.Forms为Android编写一个应用程序,我想要一个ImageButton,如以下问题所示: 问题是,只要我设置了按钮的背景,图像就无法正确显示。按钮位于图像的左上角,图像非常大。按钮显示正确 这是我的带有按钮的Xaml:Xamarin.forms 图片不´;t安装图像按钮,xamarin.forms,android-imagebutton,Xamarin.forms,Android Imagebutton,我想用Xamarin.Forms为Android编写一个应用程序,我想要一个ImageButton,如以下问题所示: 问题是,只要我设置了按钮的背景,图像就无法正确显示。按钮位于图像的左上角,图像非常大。按钮显示正确 这是我的带有按钮的Xaml: <?xml version="1.0" encoding="utf-8" ?> <ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns
<?xml version="1.0" encoding="utf-8" ?>
<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"
xmlns:android="http://schemas.android.com/apk/res/android"
mc:Ignorable="d"
x:Class="ASUE.Views.ItemsPage"
Title="AllItems"
x:Name="BrowseItemsPage">
<ContentPage.ToolbarItems>
<ToolbarItem Text="Archive" Clicked="Archive_Clicked"/>
</ContentPage.ToolbarItems>
<AbsoluteLayout>
<ScrollView AbsoluteLayout.LayoutFlags="All" AbsoluteLayout.LayoutBounds="0,0,1,1">
<StackLayout>
<ListView x:Name="ItemsListView"
ItemsSource="{Binding Items}"
VerticalOptions="FillAndExpand"
HasUnevenRows="true"
RefreshCommand="{Binding LoadItemsCommand}"
IsPullToRefreshEnabled="true"
IsRefreshing="{Binding IsBusy, Mode=OneWay}"
CachingStrategy="RecycleElement"
ItemSelected="OnItemSelected">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout Padding="10" BackgroundColor="{Binding BColor, FallbackValue='White'}">
<Label Text="{Binding Title}"
LineBreakMode="NoWrap"
Style="{DynamicResource ListItemTextStyle}"
FontSize="16" />
<Label Text="{Binding ActionTime}"
LineBreakMode="NoWrap"
Style="{DynamicResource ListItemDetailTextStyle}"
FontSize="13" />
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
</ScrollView>
<ImageButton Source="add.png" AbsoluteLayout.LayoutFlags="PositionProportional" AbsoluteLayout.LayoutBounds=".95,.95,80,80" BackgroundColor="Transparent"/>
</AbsoluteLayout>
</ContentPage>
您需要设置拐角半径
以具有圆形按钮。您还需要设置Padding
属性以缩小图像:
其中add.png是:
你可以在这里找到它:
黑色或白色我只是这样限制它的宽度和高度,这是你想要的效果吗
<ImageButton Source="add.png"
HorizontalOptions="Center"
VerticalOptions="Center"
CornerRadius="25"
WidthRequest="50"
HeightRequest="50"
AbsoluteLayout.LayoutFlags="PositionProportional"
AbsoluteLayout.LayoutBounds=".95,.95,80,80"
BackgroundColor="Accent"/>
谢谢你的帮助,但这一切都不起作用。
因此,我只是将图片作为ImageSource创建了一个普通按钮,并正确调整了图片的大小以适合该按钮。aspect属性没有帮助,也无法正常工作。我已经尝试了所有三个选项您可以显示完整的xaml吗?我还尝试了不同的图标-->相同的问题这有点帮助,图像变得更小了,但它不再是圆形,也不适合按钮的形状。我的填充像是“0,0,75,75”,当图像是圆形图像时,不必使用该技巧。对于角半径,你只需要使用一个普通的图像,它是一个简单的“+”,你可以按照你想要的方式设置背景色。
<ImageButton Source="add.png"
AbsoluteLayout.LayoutFlags="PositionProportional"
AbsoluteLayout.LayoutBounds=".1,.1,80,80"
BackgroundColor="Accent"
CornerRadius="80"
Padding="0,0,75,75"/>
<ImageButton Source="add.png"
AbsoluteLayout.LayoutFlags="PositionProportional"
AbsoluteLayout.LayoutBounds=".1,.1,80,80"/>
<ImageButton Source="add.png"
AbsoluteLayout.LayoutFlags="PositionProportional"
AbsoluteLayout.LayoutBounds=".1,.1,80,80"
CornerRadius="80"/>
<ImageButton Source="add.png"
HorizontalOptions="Center"
VerticalOptions="Center"
CornerRadius="25"
WidthRequest="50"
HeightRequest="50"
AbsoluteLayout.LayoutFlags="PositionProportional"
AbsoluteLayout.LayoutBounds=".95,.95,80,80"
BackgroundColor="Accent"/>