Firemonkey ListView scrollbar visibility

1k views Asked by At

In the Firemonkey's TListview the visibility of the scroll bar depends whether the system has a touch screen. How can I override this behavior and show vertical scrolling always when there is not enough room on the list view to display all list items?

I saw within TListViewBase.Create that the scroll visibility depends again on the function result of HasTouchTracking and this depends if TScrollingBehaviour.TouchTracking is set in SystemInformationService.GetScrollingBehaviour.

Does anyone have a glue how I can override this behavior?

2

There are 2 answers

0
Schneider Infosystems Ltd On BEST ANSWER

For Dave's proposed workaround, the touch tracking needs to be turned off as follows:

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

With this solution, however, you have to accept that the listview on touchscreen systems can no longer be scrolled with the finger.

That's why I have now opened a change request in the Embarcadero Quality Central and suggested a solution proposal by extending the TListView with a new property SuppressScrollBarOnTouchSystems (RSP-26584).

1
Dave Nottage On

A while ago I "threw together" (in a hurry) this unit to override GetScrollingBehaviour for Windows. You could do something similar for whichever platform(s) you want to override it for. In the Create method, I remove the installed service, but keep a reference to it for the parts that are not overridden, then replace it with my own.

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.