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

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

问题描述

我需要检测用户何时向下滚动到ListBox的底部,这样我才能获取接下来要显示在listBox中的25个项目,任何提示?

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 $ c>到适当的位置。

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.

我们首先添加此技巧以公开TListBox类的私有部分和受保护部分

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

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

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

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

类似这样的方法对您有用

Something like this will work for you

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天全站免登陆