Firemonkey ListView滚动条可见性



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

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

有人知道我该如何克服这种行为吗?

不久前,我(匆忙地("拼凑"了这个单元,以覆盖Windows的GetScrollingBehavior。您可以对任何要覆盖它的平台执行类似的操作。在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提出的解决方案,触摸跟踪需要关闭,如下所示:

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

然而,有了这个解决方案,你必须接受触摸屏系统上的列表视图不能再用手指滚动了。

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

最新更新