xamarin.forms - 图片不适合 ImageButton
问题描述
我想用 Xamarin.Forms 为 Android 编写一个应用程序,我想要一个像这个问题一样的 ImageButton:How to make a Floating Action Button in Xamarin Forms
问题是,一旦我设置按钮的背景,图像就无法正确显示。按钮在图片的左上角,图片超级大。按钮显示正确。
这是我的带有按钮的 Xaml:
<?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>
我希望图像与按钮大小相同
更新
我试过这个
<ImageButton Source="add.png"
AbsoluteLayout.LayoutFlags="PositionProportional"
AbsoluteLayout.LayoutBounds=".1,.1,80,80"
BackgroundColor="Accent"
CornerRadius="80"/>
<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"/>
解决方案
感谢您的所有帮助,但遗憾的是,这些都不起作用。所以我只是用图片作为 ImageSource 制作了一个普通按钮,并正确调整图片大小以适合按钮。
推荐阅读
- wildfly - Wildfly 14 出现 404 错误后出现 403 错误
- ruby-on-rails - ActiveStorage 清除问题
- botframework - 格式化 HTML bot sdk v4
- react-native - 两个错误(构建失败和命令失败:gradlew.bat app:installDebug -PreactNativeDevServerPort=8081)不断发生
- node.js - 如何更新 storage.getSignedUrl() 函数中的 Firebase 权限
- r - R中的分组和转置
- python - Cupy说它已经实现了scipy的cg,但是安装时找不到cg(共轭梯度法)
- android - 未处理的异常:查找已停用小部件的祖先是不安全的
- vue.js - 在节点单击或节点悬停时实现工具提示
- mongodb - 将 fiware orion 与 azure cosmos db mongo api 一起使用