Delphi XE5 Android-屏幕分辨率和设备配置文件 [英] Delphi XE5 Android - Screen resolution & device profiles

查看:84
本文介绍了Delphi XE5 Android-屏幕分辨率和设备配置文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始在Delphi XE5中为android开发一个应用程序,遇到了一些麻烦.第一个是在设计时为设备创建新的配置文件.我为HTC One(M7)创建了一个新的配置文件,它的屏幕为4,7,分辨率为1080x1920.当使用此类数据创建配置文件时,只有在设备上运行该图片后,我才得到图片的左上部分.从那时起,我开始运行我的应用程序,因此我可以在默认配置文件"5,1" WVGA Android Phone(480dp x 800dp:mdpi)的模式下至少测试我正在执行的代码,因为在此设置下,我看到大约75%的设计时表单大小...任何人都不知道为什么会这样,是XE5的问题,还是在手机上运行时应用程序本身?

更新:我从RAD Studio的示例项目中得出的结论是,如果我使用同样具有1080x1920分辨率的Samsung Galaxy S4模板,那么它也是适用于HTC One的正确格式.只是看不到它的设置,因为无法编辑库存资料,但是肯定不会将其设置为1080x1920,因为表单本身看起来比我创建的表单要小.

我现在知道我可以使用此设置,但只是不明白为什么会有所不同.

无论如何,现在的主要问题是,如何设置屏幕设置,以便根据设备和设备的屏幕分辨率来应用和更改屏幕设置...?

谢谢.

更新:刚从一个朋友那里得到证实,他在Nexus平板电脑上可以看到整个图片,这意味着表格的大小与delphi中设置的一样. http://en.wikipedia.org/wiki/Nexus_7_(2012_version)

Wtf?

解决方案

对于大多数手机来说,这是一个真正的问题.大多数设备都有屏幕刻度.ios拥有它,大多数现代的Android设备都拥有它.您要做的是通过将位图的尺寸乘以屏幕比例来将位图缩放到屏幕.来自我自己的代码的示例:

 函数TMandel_View.get_screenscale:单;变种ScreenService:IFMXScreenService;开始结果:= 1;如果TPlatformServices.Current.SupportsPlatformService(IFMXScreenService,IInterface(ScreenService)),则开始结果:= ScreenService.GetScreenScale;结尾;//如果结尾;//get_screenscale//过程TMandel_View.FormActivate(发送者:TObject);变种屏幕比例:单;开始如果未激活,则//初始化仅应调用一次开始FActivated:=真;//每次激活表单时均禁用初始化screenscale:= get_screenscale;FImageBitmapWidth:= FImage.Width *屏幕比例;FImageBitmapHeight:= FImage.Height *屏幕比例;FImage.Bitmap.SetSize(圆形(FImageBitmapWidth),圆形(FImageBitmapHeight));//等等...结尾;//如果结尾;//FormActivate// 

您可能想查看完整的源代码,但这差不多.

I started doing an app for android in Delphi XE5, and encountered some troubles. First one was, when creating new profile for device in design time. I created new profile for my HTC One (M7), which has 4,7" screen at 1080x1920 resolution. When created profile with such data, I only got the top left part of picture after I ran it on the device itself. So, since then I'm running my app, so I can test at least the code I'm doing, in mode with default profile " 5,1" WVGA Android Phone (480dp x 800dp: mdpi) ", since at this settings, I see about 75% of the design-time form size... Anyone has any idea why this is happening, and if that's XE5's problem, or the app's itself when ran on the phone?

Update: I figured from the sample projects of RAD studio, that if I use Samsung Galaxy S4 template, which also has 1080x1920 resolution, it's the correct form for my HTC One as well. Just can't see it's settings, since stock profiles can't be edited, but surely isn't set as 1080x1920, because the form itself looks smaller than the one I created.

I know now I can use this settings, but just don't understand why the difference.

Anyway, the main question now is, how to set up the screen settings so that they apply and change in dependence of the device and device's screen resolution...?

Thanks.

UPDATE: Just got confirmed from a friend that on his Nexus tablet he sees the whole picture, meaning the form's size just as is set in delphi. http://en.wikipedia.org/wiki/Nexus_7_(2012_version)

Wtf?

解决方案

This is a real problem for most mobile phones. Most devices have a screenscale. ios has it, most modern Android devices have it. What you have to do is to scale a bitmap to the screen by multiplying its dimensions by the screen scale. Example from my own code:

function TMandel_View.get_screenscale: Single;
var
   ScreenService: IFMXScreenService;
begin
   Result := 1;
   if TPlatformServices.Current.SupportsPlatformService (IFMXScreenService, IInterface(ScreenService)) then
   begin
      Result := ScreenService.GetScreenScale;
   end; // if
end; // get_screenscale //

procedure TMandel_View.FormActivate (Sender: TObject);
var
  screenscale: Single;
begin
   if not FActivated then  // Initialization should be called only once
   begin
      FActivated := True;  // Disable initialization each time form is activated
      screenscale := get_screenscale;
      FImageBitmapWidth := FImage.Width * screenscale;
      FImageBitmapHeight := FImage.Height * screenscale;
      FImage.Bitmap.SetSize (Round (FImageBitmapWidth), Round (FImageBitmapHeight));
// etc...
   end; // if
end; // FormActivate //

You might want to view the full sourcode but this is pretty much it.

这篇关于Delphi XE5 Android-屏幕分辨率和设备配置文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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