简体   繁体   English

用于delphi fmx应用程序的Android浮动按钮

[英]Android Floating button for delphi fmx application

I would like to know if it is possible to implement a custom button (inside a FMX application developed with RADstudio) which behaves like an Android floating button.我想知道是否可以实现一个自定义按钮(在使用 RADstudio 开发的 FMX 应用程序中),其行为类似于 Android 浮动按钮。

Floating button (Android documentation) 浮动按钮(Android 文档)

Edit #1: Using RadStudio 10.4.x, I'm now able to set the property StyleLookup of TButton to "transparentcirclebuttonstyle" and using TCircle I can draw a button that looks like an Android floating button.编辑 #1:使用 RadStudio 10.4.x,我现在可以将 TButton 的属性 StyleLookup 设置为“transparentcirclebuttonstyle”,并且使用 TCircle 我可以绘制一个看起来像 Android 浮动按钮的按钮。

Updated: Btw you can use SpeedButton with this circle image, so you can skip some routines below.更新:顺便说一句,您可以将 SpeedButton 与此圆形图像一起使用,因此您可以跳过下面的一些例程。


Prepare a png image (better 3 images with 3 scales) with your button.使用您的按钮准备一个 png 图像(最好是 3 个具有 3 个比例的图像)。

Scale 1 = 56x56
Scale 2 = 112x112
Scale 3 = 168x168

Place it in TImageList (usually in global Datamodule), add your image in list, and add 3 scales factor to a source image (Double click on item in "Source of images" list in ImageList), so one image in TImageList will have 3 scale factors.将其放入 TImageList(通常在全局 Datamodule 中),将您的图像添加到列表中,并为源图像​​添加 3 个比例因子(双击 ImageList 中“图像源”列表中的项目),因此 TImageList 中的一个图像将有 3比例因子。 Place TGlyph on a form and select your image list there.将 TGlyph 放在表单上并在那里选择您的图像列表。

Set OnClick event in Form OnCreate (because Glyph1 has no OnClick by default in Object Inspector):在 Form OnCreate 中设置 OnClick 事件(因为 Glyph1 在 Object Inspector 中默认没有 OnClick):

Glyph1.OnClick := Click;
Glyph1.HitTest := true; 

In OnClick add this code to animate:在 OnClick 中添加此代码以设置动画:

procedure TForm2.TestClick(Sender: TObject);
begin
  TAnimator.AnimateFloatWait(Glyph1, 'Opacity', 0.5, 0.2);
  TAnimator.AnimateFloat(Glyph1, 'Opacity', 1, 0.2);
end;

Or you can use TImage - it's even easier and less code than above.或者你可以使用 TImage - 它比上面的更容易和更少的代码。

Also you can use NativeAPI to draw Circle + image + shadow with antialiasing on Android/iOS with Firemonkey.您也可以使用 NativeAPI 在 Android/iOS 上使用 Firemonkey 绘制带有抗锯齿功能的圆形 + 图像 + 阴影。 http://www.cnblogs.com/onechen https://github.com/rzaripov1990/ZMaterialComponents But it's slower than a simple image. http://www.cnblogs.com/onechen https://github.com/rzaripov1990/ZMaterialComponents但它比简单的图像慢。

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

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