如何在Delphi Firemonkey/Android应用程序中为TRectangle添加触摸效果?

3
我想要在一个TRectangle中添加触摸效果动画(扩展圆形)。与默认情况下的TButtons相同 - 当你把手指放在它们上面时,它们开始绘制扩张的圆圈。
我正在寻找最简单的方法来实现这一点,最好是在FMX中(例如,从组件面板中选择某个组件,将其添加到Rect1并进行配置),而不是在代码中。
为什么不使用自定义的TButton?嗯,我只想使用这种触摸效果,不需要任何其他按钮属性/方法。

你需要玩弄与控件顶部的trectangle/tcircle相连的动画。这就是kiskis应用程序使用https://github.com/Zeus64/alcinoe的方式。 - zeus
@Kromster - 你能做到吗? - Olaf
@Olaf 不需要了。我们决定不用它,因为我们的应用程序没有必要。 - Kromster
1个回答

0

你可以使用TButtonStyleObject。将其放置在TRectangle上,使用Align = Contents即可。

请不要忘记检查你的TButtonStyleObject是否具有正确的坐标以用于TTouchAnimationAdapter属性,否则你需要手动设置它。

这是一个来自Puerto Ricostyle的TButtonStyleObject示例:

object TButtonStyleObject
  StyleName = 'Background'
  Align = Contents
  Opacity = 0.100000001490116100
  SourceLookup = 'Puerto Ricostyle.png'
  Size.Width = 184.000000000000000000
  Size.Height = 91.000000000000000000
  Size.PlatformDefault = False
  HotLink = <
    item
      CapInsets.Left = 8.000000000000000000
      CapInsets.Top = 8.000000000000000000
      CapInsets.Right = 8.000000000000000000
      CapInsets.Bottom = 8.000000000000000000
      SourceRect.Left = 98.000000000000000000
      SourceRect.Top = 195.000000000000000000
      SourceRect.Right = 159.000000000000000000
      SourceRect.Bottom = 247.000000000000000000
    end
    item
      CapInsets.Left = 12.000000000000000000
      CapInsets.Top = 12.000000000000000000
      CapInsets.Right = 12.000000000000000000
      CapInsets.Bottom = 12.000000000000000000
      Scale = 1.500000000000000000
      SourceRect.Left = 147.000000000000000000
      SourceRect.Top = 299.000000000000000000
      SourceRect.Right = 241.000000000000000000
      SourceRect.Bottom = 376.000000000000000000
    end
    item
      CapInsets.Left = 16.000000000000000000
      CapInsets.Top = 16.000000000000000000
      CapInsets.Right = 16.000000000000000000
      CapInsets.Bottom = 16.000000000000000000
      Scale = 2.000000000000000000
      SourceRect.Left = 194.000000000000000000
      SourceRect.Top = 398.000000000000000000
      SourceRect.Right = 319.000000000000000000
      SourceRect.Bottom = 501.000000000000000000
    end
    item
      CapInsets.Left = 24.000000000000000000
      CapInsets.Top = 24.000000000000000000
      CapInsets.Right = 24.000000000000000000
      CapInsets.Bottom = 24.000000000000000000
      Scale = 3.000000000000000000
      SourceRect.Left = 294.000000000000000000
      SourceRect.Top = 601.000000000000000000
      SourceRect.Right = 473.000000000000000000
      SourceRect.Bottom = 755.000000000000000000
    end>
  FocusedLink = <
    item
      CapInsets.Left = 8.000000000000000000
      CapInsets.Top = 8.000000000000000000
      CapInsets.Right = 8.000000000000000000
      CapInsets.Bottom = 8.000000000000000000
      SourceRect.Left = 97.000000000000000000
      SourceRect.Top = 195.000000000000000000
      SourceRect.Right = 160.000000000000000000
      SourceRect.Bottom = 248.000000000000000000
    end
    item
      CapInsets.Left = 12.000000000000000000
      CapInsets.Top = 12.000000000000000000
      CapInsets.Right = 12.000000000000000000
      CapInsets.Bottom = 12.000000000000000000
      Scale = 1.500000000000000000
      SourceRect.Left = 148.000000000000000000
      SourceRect.Top = 299.000000000000000000
      SourceRect.Right = 241.000000000000000000
      SourceRect.Bottom = 374.000000000000000000
    end
    item
      CapInsets.Left = 16.000000000000000000
      CapInsets.Top = 16.000000000000000000
      CapInsets.Right = 16.000000000000000000
      CapInsets.Bottom = 16.000000000000000000
      Scale = 2.000000000000000000
      SourceRect.Left = 192.000000000000000000
      SourceRect.Top = 400.000000000000000000
      SourceRect.Right = 318.000000000000000000
      SourceRect.Bottom = 504.000000000000000000
    end
    item
      CapInsets.Left = 24.000000000000000000
      CapInsets.Top = 24.000000000000000000
      CapInsets.Right = 24.000000000000000000
      CapInsets.Bottom = 24.000000000000000000
      Scale = 3.000000000000000000
      SourceRect.Left = 291.000000000000000000
      SourceRect.Top = 597.000000000000000000
      SourceRect.Right = 483.000000000000000000
      SourceRect.Bottom = 749.000000000000000000
    end>
  NormalLink = <
    item
      CapInsets.Left = 8.000000000000000000
      CapInsets.Top = 8.000000000000000000
      CapInsets.Right = 8.000000000000000000
      CapInsets.Bottom = 8.000000000000000000
      SourceRect.Left = 99.000000000000000000
      SourceRect.Top = 197.000000000000000000
      SourceRect.Right = 160.000000000000000000
      SourceRect.Bottom = 251.000000000000000000
    end
    item
      CapInsets.Left = 12.000000000000000000
      CapInsets.Top = 12.000000000000000000
      CapInsets.Right = 12.000000000000000000
      CapInsets.Bottom = 12.000000000000000000
      Scale = 1.500000000000000000
      SourceRect.Left = 148.000000000000000000
      SourceRect.Top = 299.000000000000000000
      SourceRect.Right = 241.000000000000000000
      SourceRect.Bottom = 376.000000000000000000
    end
    item
      CapInsets.Left = 16.000000000000000000
      CapInsets.Top = 16.000000000000000000
      CapInsets.Right = 16.000000000000000000
      CapInsets.Bottom = 16.000000000000000000
      Scale = 2.000000000000000000
      SourceRect.Left = 194.000000000000000000
      SourceRect.Top = 400.000000000000000000
      SourceRect.Right = 318.000000000000000000
      SourceRect.Bottom = 502.000000000000000000
    end
    item
      CapInsets.Left = 24.000000000000000000
      CapInsets.Top = 24.000000000000000000
      CapInsets.Right = 24.000000000000000000
      CapInsets.Bottom = 24.000000000000000000
      Scale = 3.000000000000000000
      SourceRect.Left = 291.000000000000000000
      SourceRect.Top = 597.000000000000000000
      SourceRect.Right = 478.000000000000000000
      SourceRect.Bottom = 749.000000000000000000
    end>
  PressedLink = <
    item
      CapInsets.Left = 8.000000000000000000
      CapInsets.Top = 8.000000000000000000
      CapInsets.Right = 8.000000000000000000
      CapInsets.Bottom = 8.000000000000000000
      SourceRect.Left = 100.000000000000000000
      SourceRect.Top = 196.000000000000000000
      SourceRect.Right = 159.000000000000000000
      SourceRect.Bottom = 247.000000000000000000
    end
    item
      CapInsets.Left = 12.000000000000000000
      CapInsets.Top = 12.000000000000000000
      CapInsets.Right = 12.000000000000000000
      CapInsets.Bottom = 12.000000000000000000
      Scale = 1.500000000000000000
      SourceRect.Left = 149.000000000000000000
      SourceRect.Top = 299.000000000000000000
      SourceRect.Right = 240.000000000000000000
      SourceRect.Bottom = 375.000000000000000000
    end
    item
      CapInsets.Left = 16.000000000000000000
      CapInsets.Top = 16.000000000000000000
      CapInsets.Right = 16.000000000000000000
      CapInsets.Bottom = 16.000000000000000000
      Scale = 2.000000000000000000
      SourceRect.Left = 194.000000000000000000
      SourceRect.Top = 399.000000000000000000
      SourceRect.Right = 317.000000000000000000
      SourceRect.Bottom = 501.000000000000000000
    end
    item
      CapInsets.Left = 24.000000000000000000
      CapInsets.Top = 24.000000000000000000
      CapInsets.Right = 24.000000000000000000
      CapInsets.Bottom = 24.000000000000000000
      Scale = 3.000000000000000000
      SourceRect.Left = 291.000000000000000000
      SourceRect.Top = 600.000000000000000000
      SourceRect.Right = 474.000000000000000000
      SourceRect.Bottom = 749.000000000000000000
    end>
  TouchAnimation.Link = <
    item
      SourceRect.Left = 238.000000000000000000
      SourceRect.Top = 195.000000000000000000
      SourceRect.Right = 298.000000000000000000
      SourceRect.Bottom = 255.000000000000000000
    end
    item
      Scale = 1.500000000000000000
      SourceRect.Left = 358.000000000000000000
      SourceRect.Top = 292.000000000000000000
      SourceRect.Right = 448.000000000000000000
      SourceRect.Bottom = 382.000000000000000000
    end
    item
      Scale = 2.000000000000000000
      SourceRect.Left = 478.000000000000000000
      SourceRect.Top = 389.000000000000000000
      SourceRect.Right = 598.000000000000000000
      SourceRect.Bottom = 509.000000000000000000
    end
    item
      Scale = 3.000000000000000000
      SourceRect.Left = 716.000000000000000000
      SourceRect.Top = 585.000000000000000000
      SourceRect.Right = 897.000000000000000000
      SourceRect.Bottom = 765.000000000000000000
    end>
end

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接