How are you resizing controls on Android for different phone sizes?

I am using the emulator and must’ve created a medium-sized phone. I created a new one for a smaller phone and see the controls don’t fit well. I like the control lock as we have in desktop, but for purposes like this, I like the auto layout feature in iOS.

So what are you doing to account for different phone sizes? Are you getting the screen size dimensions and coming up with some calculations to shrink/grow controls as needed? Or are you doing something else?

I just started with an Android project and am looking for ways to help with the layouts of different sizes

2 Likes

Hi Ryaz, I too have seen difficulties with aligning and resizing objects on the screen in Android.
Until the Xojo Team gives us solutions, I chose the option to reposition and resize objects manually when opening the screen.
Bye
Gabriel

As complex as constraints are on iOS, they are still far superior to locks.

3 Likes

Android has multiple layout capabilities. Constraint layout is one of those.

By the way, Constraint Layout is what devs use 97% of the time.

That screenshot looks more like springs & struts than constraints.

Visual cues of the anchors of the constraints. In Android you can drag the anchors and build the layout and the layout design code changes accordingly.

What are you all doing about it? On opening and every time you change the orientation, or modification of the App’s width (since the user can now often choose to display two applications side by side, for example, even when our app is already open/displayed), do you calculate the positions of each control according to the height and width of the screen?

I am using a factor for height and width to resize the controls and reshape the screen upon open. Tested on different Android phone sizes, and it works, but I am noticing the simulator crashes when I quit the app. I verified no simulator crash when I commented out the code below and then a crash when uncommented. Should this be a concern? And is there a better way to resize/reshape? Again, noticing only the simulator crashing, not the app itself

In screen.opening:

'designed on medium Android phone, so using that as reference point:  W 393, H 781
DevSizeFactorW = self.Size.Width / 393
DevSizeFactorH = self.Size.Height / 781

canReview.Height = 145 * DevSizeFactorH
canExams.Height = 145 * DevSizeFactorH
canStats.Height = 145 * DevSizeFactorH

canReview.top = canExams.Top + canExams.Height + 8
canStats.Top = canReview.Top + canReview.Height + 8

canSettings.Top = canStats.Top + canStats.Height + 15
canAbout.Top = canSettings.Top + canSettings.Height + 8

I found a fix to the simulator crashing when the app is quit using the above code. I moved the code from the screen’s .Opening event to a method, and in .Opening, added a timer.calllater. Tested this, and no simulator crash. Hope this helps someone!

1 Like

Maybe we can get Xojo to add an event for when it’s safe to layout controls.

1 Like

On Desktop, that was Open and part of the reason it occurs after every control’s Open event…