Delphi/FMX:如何在所有先前添加的顶部对齐组件下添加动态创建的顶部对齐组件,而不是从顶部添加第二个? [英] Delphi/FMX: How to add a dynamically created top-aligned component under all previously added top-aligned components, instead of second from the top?

查看:62
本文介绍了Delphi/FMX:如何在所有先前添加的顶部对齐组件下添加动态创建的顶部对齐组件,而不是从顶部添加第二个?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Delphi和FMX为Android制作一个应用程序.在按钮的onclick过程中,我动态创建了一个TPanel(其中包含一些组件),然后将其添加到TVertScrollBox中.我希望TPanels彼此堆叠,所以我将Align属性设置为Top.

I am making an app for Android with Delphi and FMX. In the onclick-procedure of a button I dynamically create a TPanel (with some components in it) which I then add to a TVertScrollBox. I want the TPanels to stack on top of each other, so I set the Align property to Top.

procedure TMainForm.AddGroupButtonClick(Sender: TObject);
var Group : TPanel;
begin
   Group := TPanel.Create(Self);
   Group.Parent := Groups;         // where Groups is a TVertScrollBox on the form
   Group.Align := TAlignLayout.Top;

   //Then I create some other components and set their Parent to Group
end;

用户可能希望将新的TPanel添加到所有其他TPanels下.但是,除非以前没有添加TPanels,否则每个新的TPanel都将直接添加到最上面的一个,即从顶部开始的第二个.

A user would probably expect the new TPanel to be added under all the other TPanels. However, unless there's no TPanels added previously, every new TPanel is added directly under the topmost one, i.e. second from the top.

这是为什么?如何在所有以前添加的TPanel下添加新的TPanel?

Why is this and how do I add the new TPanel under all the previously added ones?

我在这里看到了类似的问题,但是他们使用的是VCL,显然有可以更改的顶级属性.不过,使用FMX组件时似乎没有一个.

I saw a similar question on here, but they were using VCL, where there apparently is a Top-property you can change. There doesn't seem to be one when working with FMX components though.

推荐答案

在创建新的 Firemonkey 面板时,默认情况下其 Position 属性是 X =0,Y = 0 .

When you create a new Firemonkey panel, its Position property is by default X=0, Y=0.

设置 Align:= TAlignLayout.Top; 时,它将与先前放置的组件进行比较,发现在 Y = 0 处已经有一个面板,并挤压新面板在现有面板下面.

When you set Align := TAlignLayout.Top; it compares with previously placed components, finds that there is already a panel at Y = 0 and squeezes the new panel next below that existing panel.

要将新面板放置在所有其他面板集的下方

To place the new panel below all other panels set

...
Group.Position.Y := 1000; // any sufficiently large value (bigger than the last panel's Y)
Group.Align := TAlignLayout.Top;

这篇关于Delphi/FMX:如何在所有先前添加的顶部对齐组件下添加动态创建的顶部对齐组件,而不是从顶部添加第二个?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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