【发布时间】:2014-02-06 23:15:14
【问题描述】:
据我了解,在 Delphi for Android 中,我以像素为单位设置组件的宽度和高度。因此,在各种屏幕上都会有明显的差异。我希望有一种方法可以在 dp units 中设置大小而不是(或类似的)。
ActionBar: TToolBar;
ActionBar := TToolBar.Create(Form1);
ActionBar.Align := TAlignLayout.alTop;
ActionBar.Height := 30.0;
ActionBar.Parent := Form1;
如您所见,我手动设置了尺寸。我拒绝使用布局的原因是我将 FMX 与原生 Android 组件混合在一起。
我希望我的操作栏在各种屏幕上看起来都很漂亮:) 实现这一目标的正确方法是什么?
【问题讨论】:
-
您可以使用表单高度/宽度的百分比吗?
-
@MikeSutton,我今天想到的最好的方法是计算 dp 常数。根据 Android 开发指南
px = dp * (dpi / 160);、dp = px / (dpi / 160);。刚才我找到了dp := px * SharedActivityContext.getResources.getDisplayMetrics.density;
标签: android delphi android-layout firemonkey delphi-xe5