Recent

Author Topic: Androids Relative Position/Dimension  (Read 7263 times)

kupferstecher

  • Hero Member
  • *****
  • Posts: 583
Androids Relative Position/Dimension
« on: October 26, 2017, 09:05:27 pm »
I just started my first trials on programming Android with Lazarus. I chose LazToApk with the CustomDrawn interface. The installation made some difficulties, but I got it running, the example compiled well. Some of the components have strange behaviour, probably those are not really supported.

For small apps the relative position and dimensions of the controls are helpful. But I wonder if there is any possibility to suppress this behaviour and do a static approach. The background is a desktop software that I want to port to Android. The relative design destroys the whole arrangements so I see no chance for me for porting.

What I tried is to constrain the dimensions of a panel to a fixed value. This works for the panel itself, but the child controls are scaled independently of it and will be even outside of my container panel when running the application. So this failed...

Another idea was to set the apps dimension after startup to those of the window while designing, in the hope that all controls are in correct size and position. But this also failed. i guess that the scaling is done during compilation.

So is there any chance to achive a 1 to 1 layout from design to running independent of the devices screen dimensions? E.g. creating all controls (manualy) dynamically in the code.

Thanks for any help or hints!

Regards~

kupferstecher

  • Hero Member
  • *****
  • Posts: 583
Re: Androids Relative Position/Dimension
« Reply #1 on: November 01, 2017, 09:58:13 pm »
Now one with a hint or anything?

DonAlfredo

  • Hero Member
  • *****
  • Posts: 1739
Re: Androids Relative Position/Dimension
« Reply #2 on: November 01, 2017, 10:20:54 pm »
I would advice against CustomDrawn on Android.
Its not that easy to use, very limited and hardly maintained.

You should use LAMW. Search the forum for it !

kupferstecher

  • Hero Member
  • *****
  • Posts: 583
Re: Androids Relative Position/Dimension
« Reply #3 on: November 01, 2017, 10:44:29 pm »
Yes, LAMW seems very popular.

Do you know if its possible to achive a non-relative layout with LAMW?

I want to press a desktop-style programm into android, thats why I need the absolute coordinates. Just like if someone would try to port the Lazarus IDE onto Android.

jmpessoa

  • Hero Member
  • *****
  • Posts: 2301
Re: Androids Relative Position/Dimension
« Reply #4 on: November 01, 2017, 10:59:45 pm »

Hello  kupferstecher!

Can you show  what GUI you need to "press"  from desktop?

I will try with LAMW...
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

kupferstecher

  • Hero Member
  • *****
  • Posts: 583
Re: Androids Relative Position/Dimension
« Reply #5 on: November 01, 2017, 11:42:09 pm »
Hello jmpessoa.

see attached a screenshot. Its a visualisation for mikrocontroller data through serial port and ethernet. The user can arrange instruments randomly. All the instruments consist of several standard components like buttons, labels, panels, chart etc and custom controls, user drawn. The inner and outer alignment is all done with pixel coordinates. The menue I could change and simplify, but for the instruments I don't see a possibility. On the other hand all instruments are dynamically created and not from the form designer, perhaps this gives further options?

Regards

jmpessoa

  • Hero Member
  • *****
  • Posts: 2301
Re: Androids Relative Position/Dimension
« Reply #6 on: November 02, 2017, 01:06:57 am »


Hello kupferstecher.

What about a minimalistic App.... test only?
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

kupferstecher

  • Hero Member
  • *****
  • Posts: 583
Re: Androids Relative Position/Dimension
« Reply #7 on: November 02, 2017, 12:04:32 pm »
Hello jmpessoa,

attached a minimum Projekt.

I'm beginnning to understand the scaling behaviour now:
If the control is created in the forms OnCreate, then the form dimensions of designtime are assumed and the control is alligned to that size. While Create the Form is scaled to the actual screen size and with it all controls.
However, if the controls are created after the forms create, then they will get the actual dimensions defined in SetSize (which is nice).

Does this work in the same way with LAMW?


The attached project works with LazToAPK, because of the filesize I couln't attach the apk.

jmpessoa

  • Hero Member
  • *****
  • Posts: 2301
Re: Androids Relative Position/Dimension
« Reply #8 on: November 02, 2017, 07:16:58 pm »
Quote
Does this work in the same way with LAMW?

LAMW has total control of dimension and position of every visual component:
[note: LAMW visual component are just Android visual component ...]

You need only config and handle this properties:

Quote
  LParamWidth: TLayoutParams;       
  LParamHeight: TLayoutParams;

  PositionRelativeToParent: TPositionRelativeToParentSet;
  PositionRelativeToAnchor: TPositionRelativeToAnchorIDSet;


Quote
  TLayoutParams = (lpMatchParent, lpWrapContent, lpHalfOfParent, lpOneQuarterOfParent, lpTwoThirdOfParent,
                   lpOneThirdOfParent, lpOneEighthOfParent,lpThreeEighthOfParent, lpFiveEighthOfParent,
                   lpSevenEighthOfParent, lpOneSixthOfParent, lpFiveSixthOfParent, lpOneFifthOfParent,
                   lpTwoFifthOfParent, lpThreeFifthOfParent, lpThreeQuarterOfParent,
                   lpFourFifthOfParent, lpNineTenthsOfParent, lp95PercentOfParent, lp99PercentOfParent,
                   lp16px, lp24px, lp32px, lp40px, lp48px, lp72px, lp96px, lpExact, lpUseWeight);

Quote
TPositionRelativeToParent = (rpBottom,
                               rpTop,
                               rpLeft,
                               rpRight,
                               rpStart,
                               rpEnd,
                               rpCenterHorizontal,
                               rpCenterInParent,
                               rpCenterVertical);

Quote
  TPositionRelativeToAnchorID = ( raAbove,
                                  raBelow,
                                  raToStartOf,
                                  raToEndOf,
                                  raToLeftOf,
                                  raToRightOf,
                                  raAlignBaseline,
                                  raAlignTop,
                                  raAlignBottom,
                                  raAlignStart,
                                  raAlignEnd,
                                  raAlignLeft,
                                  raAlignRight);

And more, you can handle device rotate orientation.....

« Last Edit: November 02, 2017, 07:26:05 pm by jmpessoa »
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

kupferstecher

  • Hero Member
  • *****
  • Posts: 583
Re: Androids Relative Position/Dimension
« Reply #9 on: November 02, 2017, 07:57:44 pm »
These are quite some parameters... Do I see it correct that they all define a relative relationship to the parent, so no absolut positions and dimensions are possible?

In my use case would you recommend me using LAMW or CustomDrawn?

Thanks a lot!

jmpessoa

  • Hero Member
  • *****
  • Posts: 2301
Re: Androids Relative Position/Dimension
« Reply #10 on: November 02, 2017, 08:14:03 pm »
Quote
These are quite some parameters...

Yes, but all this stuff are handled in design time [LAMW form designer]

Quote
In my use case would you recommend me using LAMW or CustomDrawn?

Well, you can install LAMW and try layouting some GUI.... then you will have the information to make your decision ...

You can start with  Laz4Android + LAMW

reference:
https://github.com/jmpessoa/lazandroidmodulewizard/blob/master/readme_get_start.txt
« Last Edit: November 02, 2017, 08:20:06 pm by jmpessoa »
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

kupferstecher

  • Hero Member
  • *****
  • Posts: 583
Re: Androids Relative Position/Dimension
« Reply #11 on: November 02, 2017, 08:21:51 pm »
OK, thanks for the explanations!
I guess I'll have some further trials with the CustomDrawn first, as it seems to be closer to the LCL way of GUI-programming.

Regards~

Handoko

  • Hero Member
  • *****
  • Posts: 5154
  • My goal: build my own game engine using Lazarus
Re: Androids Relative Position/Dimension
« Reply #12 on: November 03, 2017, 05:15:10 am »
Sorry, I want to ask an off topic question.
Can your CustomDrawn Android app run correctly on devices using Android 5 and above?

I never succeed on my Android 5 phone, the apk installations were smooth but they always failed to start. I search the forum, some said CustomDrawn has issue with Android 5 and above. That's why I choose LAMW instead of CustomDrawn. Have the CustomDrawn Android 5/+ issue been solved?

I maybe do not fully understand about the absolute coordinate you said. But I think you can solve it by write your own visual components. I am doing it currently.

The concept is the programmer define its coordinate size of the screen on the beginning then all the screen outputs will be calculated based on the size. It works good on any screen resolutions and aspects because the drawing engine will scale it down/up properly. The bad thing is the text output, unproportional scaling will make the texts look ugly, but I already solved this issue using my own invent logic.

The basic concept already proven to run correctly on my tests on Windows and Linux. Now I'm making the module to support Android platform. Unfortunately the progress is slow because programming is just my hobby, I'm doing in only when I have time.

I got this idea of screen drawing from QB64. It is an interesting tool, it can produce Android app too. But I prefer Pascal syntax instead of BASIC.

CC

  • Full Member
  • ***
  • Posts: 149
Re: Androids Relative Position/Dimension
« Reply #13 on: November 03, 2017, 10:15:51 am »
An interesting approach would be to use LAMW's jView+jcanvas instance as the form surface and implement a rendering engine  to draw the controls on this canvas. Plus creating event handling for the controls drawn there. This would bring all the benefits of custom drawn controls a LAMW's android ecosystem together. The android way of layouting makes sense, but currently it is not implemented properly and could be improved.  There are control elements which are not scaled like fonts, margins ... 

Maybe even the LCL or a little more likely FPGUI can be enhanced to use jCanvas to draw its controls.  If this concept was implementable adding a HTML5 canvas would be the next step to create a UI which draws itself on on any surface.

All this would require an  other level of abstraction which can be tricky.
« Last Edit: November 03, 2017, 10:56:45 am by CC »

kupferstecher

  • Hero Member
  • *****
  • Posts: 583
Re: Androids Relative Position/Dimension
« Reply #14 on: November 03, 2017, 10:40:17 am »
Can your CustomDrawn Android app run correctly on devices using Android 5 and above?
Hello Handoko,
thats a good question! I didn't know about that issue. And searching through the forum for that topic doesn't bring up an hint that it is solved or even worked on. I couldn't test as I don't have any Android 5 device by hands.

Quote from: Handoko
Have the CustomDrawn Android 5/+ issue been solved?
@all: Does someone know about it?

Quote from: Handoko
I maybe do not fully understand about the absolute coordinate you said
Lets say the user of my program designs a screen with width 800 on his computer. Then the apk-surface also should be exactly 800 with padding the rest area of the display if the display is larger, or providing a scrolling behaviour to reach the outside content if the display is smaller than the 800. I.e. I want to use the desktop-approach but on Android.

Quote from: Handoko
But I think you can solve it by write your own visual components [...]
The concept is the programmer define its coordinate size of the screen on the beginning then all the screen outputs will be calculated based on the size.
That does sound promising. Can you post a little snippet of how the dimensions are set? The properties jmpessoa posted, didn't look like its possible to work with pixels.
Does writing own visual contents work in the same way as with TCustomControl in LCL?

Quote from: Handoko
Unfortunately the progress is slow because programming is just my hobby
Same here, same here ;-)

 

TinyPortal © 2005-2018