13 posts / 0 new
Last post
GarthWood
GarthWood's picture
Offline
Joined: 26 Aug 2011
Posts:
Widget Alignment

Hi

I've written a basic app that just displays images on screen, which I use as buttons. They work find but for some reason the alignment just doesn't work at all, unless I'm just not understanding how things should work.

I create a layout which is the screen width and height that has 6 rows. I then add an image to the Layout (I do this by setting the parent of the image to the that of the layout).

Now I can't align images, not sure why? So instead I center align the layout, but it always remains left aligned. I then created another layout which I added the image to and aligned that in the main layout, but still no luck.

I'm developing for Android but it doesn't even work in the MoSync emulator.

Thanks
Garth

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Sam Pickard
rival's picture
Offline
Mobile Archmage
Joined: 19 Mar 2009
Posts:

Hi, layout has higher priority then alignment. Alignments only work with the widget, and layout has the power to move them. Alignment doesn't work within a cell. You can set margins on a layout, but it is the same for each cell.

What you can do I think in your instance is to not set autosizeX on the images. If you set the width of the image to be the width of the screen, then the image widget will have that size, but the image itself won't be scaled. It should be placed in the centre. Try it and let me know.

GarthWood
GarthWood's picture
Offline
Joined: 26 Aug 2011
Posts:

Thanks. Yes that does work, but the problem is that the mouse events get processed outside of the image, because the extents of the 'actual' image are right across the screen.

Is padding the only way to do this? Or do i have to create more layouts on the left and right of the image?

Sam Pickard
rival's picture
Offline
Mobile Archmage
Joined: 19 Mar 2009
Posts:

Two ways immediately spring to mind.

The first way is not to use a layout at all. If you create an blank image as the background, you can add your images as children, and position them exactly where you want them on screen. You just have to track how much vertical space they are taking yourself.

The second way is to use sub-layouts, but you will probably need to calculate the amount of padding required on each side, and each column in a layout is the same width.

I'd probably do it the first way.

GarthWood
GarthWood's picture
Offline
Joined: 26 Aug 2011
Posts:

I'll give the one a try. Thanks a lot.

Miguel Augusto
miguelmaugusto's picture
Offline
Mobile Wizard
Joined: 19 Dec 2011
Posts:

Hi GarthWood,

Did that actually work? I'm having the same difficulties. It's very annoying actually. I've been trying with children layouts, but it only leads me to frustration and no results.

What was the solution you sticked with?

Miguel Augusto
miguelmaugusto's picture
Offline
Mobile Wizard
Joined: 19 Dec 2011
Posts:

I'm not getting the second way to work. Although I'm using widgetSkins to set the button layouts. I have to use them to be able to set the selected and unselected images. The padding just isn't working with anything other than text :-(

Sam Pickard
rival's picture
Offline
Mobile Archmage
Joined: 19 Mar 2009
Posts:

OK, Layout has two properties you can set setMarginX and setMarginY - try those.

Miguel Augusto
miguelmaugusto's picture
Offline
Mobile Wizard
Joined: 19 Dec 2011
Posts:

Still no luck :-( Do the children get forced to follow its parents alignments? Is there a difference between setting the parent at layout creation and only adding it at the end of setting the childrens properties?

Sam Pickard
rival's picture
Offline
Mobile Archmage
Joined: 19 Mar 2009
Posts:

Are you using NativeUI? No, there is no difference in with regards to changing the children's properties. Layouts are there to set the position of other widgets.

Miguel Augusto
miguelmaugusto's picture
Offline
Mobile Wizard
Joined: 19 Dec 2011
Posts:

No NativeUI. Only MAUIs.

Sam Pickard
rival's picture
Offline
Mobile Archmage
Joined: 19 Mar 2009
Posts:

OK, I'm going to need to see the whole project. Can you zip (not rar) it up, but without the FinalOutput and Output folders. Setting marginX and marginY should definitely move the widgets in from the borders of the layout in MAUI.

Miguel Augusto
miguelmaugusto's picture
Offline
Mobile Wizard
Joined: 19 Dec 2011
Posts:

OK, I gave it another try with an other layout, and yes that does work.
Thanks again, Sam! :-)