【问题标题】:Firemonkey ListView scrollbar visibilityFiremonkey ListView 滚动条可见性
【发布时间】:2019-10-31 16:43:25
【问题描述】:

在 Firemonkey 的TListview 中,滚动条的可见性取决于系统是否具有触摸屏。当列表视图上没有足够空间显示所有列表项时,如何覆盖此行为并始终显示垂直滚动?

我在TListViewBase.Create 中看到滚动可见性再次取决于HasTouchTracking 的函数结果,这取决于TScrollingBehaviour.TouchTracking 是否设置在SystemInformationService.GetScrollingBehaviour 中。

有没有人知道我可以如何覆盖这种行为?

【问题讨论】:

    标签: delphi firemonkey touchscreen tlistview tscrollbox


    【解决方案1】:

    不久前,我“拼凑”(匆忙地)这个单元来覆盖 Windows 的 GetScrollingBehaviour。您可以为要覆盖它的任何平台执行类似的操作。在 Create 方法中,我删除了已安装的服务,但为未被覆盖的部分保留对它的引用,然后将其替换为我自己的。

    unit DW.ScrollingBehaviourPatch.Win;
    
    // This unit is used for testing of "inertial" scrolling of listviews etc on devices that do not have touch capability
    
    interface
    
    implementation
    
    uses
      FMX.Platform;
    
    type
      TPlatform = class(TInterfacedObject, IFMXSystemInformationService)
      private
        class var FPlatform: TPlatform;
      private
        FSysInfoService: IFMXSystemInformationService;
      public
        { IFMXSystemInformationService }
        function GetScrollingBehaviour: TScrollingBehaviours;
        function GetMinScrollThumbSize: Single;
        function GetCaretWidth: Integer;
        function GetMenuShowDelay: Integer;
      public
        constructor Create;
        destructor Destroy; override;
      end;
    
    { TPlatform }
    
    constructor TPlatform.Create;
    begin
      inherited;
      if TPlatformServices.Current.SupportsPlatformService(IFMXSystemInformationService, FSysInfoService) then
        TPlatformServices.Current.RemovePlatformService(IFMXSystemInformationService);
      TPlatformServices.Current.AddPlatformService(IFMXSystemInformationService, Self);
      FPlatform := Self;
    end;
    
    destructor TPlatform.Destroy;
    begin
      //
      inherited;
    end;
    
    function TPlatform.GetCaretWidth: Integer;
    begin
      Result := FSysInfoService.GetCaretWidth;
    end;
    
    function TPlatform.GetMenuShowDelay: Integer;
    begin
      Result := FSysInfoService.GetMenuShowDelay;
    end;
    
    function TPlatform.GetMinScrollThumbSize: Single;
    begin
      Result := FSysInfoService.GetMinScrollThumbSize;
    end;
    
    function TPlatform.GetScrollingBehaviour: TScrollingBehaviours;
    begin
      Result := [TScrollingBehaviour.Animation, TScrollingBehaviour.TouchTracking];
    end;
    
    initialization
      TPlatform.Create;
    
    end.
    

    【讨论】:

    • 感谢 Dave 提供的这种方法。我必须仔细检查这个解决方案,因为在其他情况下,触摸屏支持对于 UI 处理仍然很重要。
    【解决方案2】:

    对于 Dave 建议的解决方法,触摸跟踪需要按如下方式关闭:

    function TPlatformListViewWorkaround.GetScrollingBehaviour: TScrollingBehaviours;
    begin
      result := fSysInfoService.GetScrollingBehaviour - [TScrollingBehaviour.TouchTracking];
    end;
    

    但是,使用此解决方案,您必须接受无法再用手指滚动触摸屏系统上的列表视图。

    这就是为什么我现在在 Embarcadero Quality Central 中打开了一个更改请求,并通过使用新属性 SuppressScrollBarOnTouchSystems (RSP-26584) 扩展 TListView 来提出解决方案建议。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-06-02
      • 2016-02-21
      • 2015-04-20
      • 2011-10-03
      • 1970-01-01
      • 1970-01-01
      • 2023-03-17
      相关资源
      最近更新 更多