检测Delphi FMX ListBox何时滚动到底部? [英] Detect when Delphi FMX ListBox is scrolled to the bottom?

查看:22
本文介绍了检测Delphi FMX ListBox何时滚动到底部?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要检测用户何时在 ListBox 中向下滚动到底部,以便获取接下来的 25 个项目以显示在 listBox 中,有什么提示吗?

I need to detect when the user has scrolled down to the bottom in a ListBox , so that I can fetch the next 25 items to show in the listBox, Any Tip?

推荐答案

好的,让我们分解一下,首先我们去 ScrollToItem 在 FMX.ListBox 单元中

Okay so let us break this down, first we go to ScrollToItem in FMX.ListBox unit

procedure TCustomListBox.ScrollToItem(const Item: TListBoxItem);
begin
  if (Item <> nil) and (Content <> nil) and (ContentLayout <> nil) then
  begin
    if VScrollBar <> nil then
    begin
      if Content.Position.Y + Item.Position.Y + Item.Margins.Top + Item.Margins.Bottom + Item.Height >
        ContentLayout.Position.Y + ContentLayout.Height then
        VScrollBar.Value := VScrollBar.Value + (Content.Position.Y + Item.Position.Y + Item.Margins.Top +
          Item.Margins.Bottom + Item.Height - ContentLayout.Position.Y - ContentLayout.Height);
      if Content.Position.Y + Item.Position.Y < ContentLayout.Position.Y then
        VScrollBar.Value := VScrollBar.Value + Content.Position.Y + Item.Position.Y - ContentLayout.Position.Y;
    end;
    if HScrollBar <> nil then
    begin
      if Content.Position.X + Item.Position.X + Item.Margins.Left + Item.Margins.Right + Item.Width >
        ContentLayout.Position.X + ContentLayout.Width then
        HScrollBar.Value := HScrollBar.Value + (Content.Position.X + Item.Position.X + Item.Margins.Left +
          Item.Margins.Right + Item.Width - ContentLayout.Position.X - ContentLayout.Width);
      if Content.Position.X + Item.Position.X < 0 then
        HScrollBar.Value := HScrollBar.Value + Content.Position.X + Item.Position.X - ContentLayout.Position.X;
    end;
  end;
end;

现在如您所见.该过程检查许多值(边距、填充、顶部......),然后通过将 VScrollBar.Value 设置到适当的位置来移动 VScrollBar.

Now as you can see. the procedure checks for many values (margins, paddings, top, ....) and then moves VScrollBar by setting VScrollBar.Value to the appropriate position.

您想知道垂直滚动条何时到达底部.

You want to know when the Vertical scroll bar has reached the bottom.

所以我们使用与我对列表视图的其他答案相同的想法.

so we use the same idea as my other answer for the list view.

我们首先添加这个 hack 来暴露 TListBox 类的私有和受保护部分

We first add this hack to expose the private and protected parts of TListBox class

TListBox = class(FMX.ListBox.TListBox)
  end;

将其添加到列表框所在的表单中,然后使用 VScrollChange(Sender: TObject); 事件并对 if 条件进行逆向工程.

add that to the form where the listbox is and then use the VScrollChange(Sender: TObject); event and reverse engineer the if conditions.

这样的东西对你有用

procedure TForm1.ListBox1VScrollChange(Sender: TObject);
var
  S:single;
begin
  S:= ListBox1.ContentRect.Height;

  if ListBox1.VScrollBar.ValueRange.Max = S + ListBox1.VScrollBar.Value then
    Caption := 'hit'
  else
    Caption := 'no hit';
end;

在尝试解决这些类型的问题时,请始终寻找 ScrollToControl 函数并从中获得灵感.上面的代码处理添加到滚动框中的简单项目.如果您对边距或填充有任何问题,只需改进公式即可解决问题.

when trying to solve these types of problems always look for a ScrollToControl function and get the inspiration from there. The code above is working with simple items added to the scroll box. if you have any problems with margins or paddings just evolve the formula to cope with that.

这篇关于检测Delphi FMX ListBox何时滚动到底部?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆