Layout Variants

Merlot2309

Active Member
Licensed User
Longtime User
Hello,

Finally put my species translator for bird names on the Market ( https://market.android.com/details?id=Species.Translator&feature=search_result ) and someone was so nice to mail me that the layout was wrong for the Samsung Galaxy S-2.

Grrrrrrrr and :BangHead:

So I added an AVD: 480x800 with a 240dpi (already had various sizes, all with 160dpi).
In the Designer I added a Layout Variant with the same values.

Now when I run this emulator variant the Device details in the Designer shows: 320x480, scale = 1.5(240dpi)

To be honoust I find this the most horrible part of developing, maybe I still don´t get it, ha, ha.

So my questions:
- Is it correct that the Designer shows a different size?
- I guess I have to use this size and dpi in the code in order to get it running correct on a 480x800 with 240dpi?
- Shouldn´t the text size of a View be linked to a Layout Variant?
Now it´s fixed for all Layout Variants.

Thank you very much in advance.

Helen.
 

Harris

Expert
Licensed User
Longtime User
I agree. Designing different layouts is for different variants and dpi is frustrating. Thats why I asked about ICS. I guess the offical word is not out yet based on the scant respense.

Your last question of text size also stumped me. I found that changing the font size value for one variant also changed it for the others - whereas the size and placement of the view remained intact (as expected). Not exactly what one would want.

Thanks

Mike
 
Upvote 0

kickaha

Well-Known Member
Licensed User
Longtime User
As far as font size goes, it is automatically scaled for the device. Therefore you do not need to alter the size for different res devices.
 
Upvote 0

Merlot2309

Active Member
Licensed User
Longtime User
Hello and thanks!

Yep, I did read the Wiki various times before and decided this morning to follow the example and added a layout for the resolution 480x800 - density: 240.
To make my life easier I copied the .bal file and removed the Layout Variants which were redundant in each .bal file.

After some strugling, comparing, etc. I again added a 480x800 - density: 240 Layout Variant to the original layout and .......... now the layout showed ok, including the font size on screen.

So, no idea what was wrong yesterday :cool:

And last but not least: it took me a while to see that the value shown in the Designer was the value when you connect the Designer to an AVD (a big oepppps for not seeing that). Well, the Variants puzzle starts to sink in, she says hopefuly.

Greets,
Helen.
 
Upvote 0

nfordbscndrd

Well-Known Member
Licensed User
Longtime User
I don't know if you caught this in the Wiki, but when I create layouts for different size devices, I put them in separate .bal files, which I believe is what you said you did, and then I open my app in two different instances of B4A so that I can open two instances of Designer, each with a different layout, and display them in different sized emulators. This makes it easier to compare the layouts.
 
Upvote 0

kickaha

Well-Known Member
Licensed User
Longtime User
I don't know if you caught this in the Wiki, but when I create layouts for different size devices, I put them in separate .bal files, which I believe is what you said you did, and then I open my app in two different instances of B4A so that I can open two instances of Designer, each with a different layout, and display them in different sized emulators. This makes it easier to compare the layouts.

Wouldnt that mean you have to write some code that decides which layout to load? I find it easier to put them all in one layout file and let the system sort itself out.
 
Upvote 0

nfordbscndrd

Well-Known Member
Licensed User
Longtime User
Wouldnt that mean you have to write some code that decides which layout to load? I find it easier to put them all in one layout file and let the system sort itself out.

Yes. Why the system doesn't always "sort itself out" satisfactorily is discussed on the Wiki page linked above. In particular:

If you change the text of any view it will be changed in all variants automatically. However if you change the position or size of a view it will only affect the current variant.

For example, I may be able to use text on a 10" tablet which I have to abbreviate to fit on a 7" or 4" device, and that can't be done if all variants are in the same layout file.

Also:

both the Xoom, at 10.1", and the Archos A70, at 7", have a scale of 1. This means that Android will not change the size of the views despite the increase in number of pixels, which means that the same layout on the Xoom will look much smaller than on the A70. (See the screen shots in the Introduction, above.) One way to adjust for this is to do a separate layout for 1280x800x160 devices in which you manually enlarge all the views, the text sizes, etc.

The code to load the correct layout file is pretty simple. Sample code for loading layout files is shown at the Wiki page linked above. If that code seems overly complicated compared to the rest of your app, then your app is probably simple enough not to need it anyway.
 
Upvote 0

kickaha

Well-Known Member
Licensed User
Longtime User
Fair point about using extended text if the space is available, but if a device has a greater number of pixels, you can define a variant with the appropriate screen sizes and adjust layout positions without resorting to separate .bal files. For example I tend to have 480x640x1 and 480x800x1 in the same file to take advantage of the extra screen size of one of the devices I use.

Having said that, I am starting to veer towards adding and scaling all views in code. it all comes down to using whatever method best works for a particular app.
 
Upvote 0

nfordbscndrd

Well-Known Member
Licensed User
Longtime User
I am starting to veer towards adding and scaling all views in code. it all comes down to using whatever method best works for a particular app.

If you have a tightly packed layout like my big app does, there's no choice but to adjust things in code. My 7" Archos has its menu space on the right side of the screen (in landscape) while my 10.1" Toshiba Thrive has it on the bottom, so I have to adjust for those (and other activity size differences) in code -- not just scaling but moving views around to make up for the aspect ratio differences. Compared to all those adjustments, loading different .bal files is nothing. My Activity_Create sub is 250 lines long, and majority of that is fine-tuning the placement of views.

A layout in this app has about 200 views in it. Getting them all placed properly would be almost impossible using code to add them instead of a layout file. But like you said, whatever works best for a particular app.
 
Upvote 0

Merlot2309

Active Member
Licensed User
Longtime User
Hi,

Using AVD works well for me now. Luckely I only have about 30 views in this little app.

How many Layout Variants do you use?
In the Market statistics I saw that the Galaxy S-2 is quite popular.

Greets,
Helen.
 
Upvote 0

nfordbscndrd

Well-Known Member
Licensed User
Longtime User
Right now I'm set up for three -- 800x480x240 (4" phones), 800x480x160 (7" tablets), 1280x800x160 (10" tablets), but before I release my app, I'll probably add one for 1024x600x170 (7" tablets) since more 7" tablets are coming out in that size.

Despite all the different sized 7" and 10" tablets, they all have a scale of 1, so Android would not make any automatic adjustments for their different sizes and number of pixels.
 
Upvote 0

hackhack

Active Member
Licensed User
Longtime User
Finally put my species translator for bird names on the Market ( https://market.android.com/details?id=Species.Translator&feature=search_result ) and someone was so nice to mail me that the layout was wrong for the Samsung Galaxy S-2.

Looks a bit short on the Asus Transformer as well. And personally I don't like being forced to use portrait mode, but hey ho.

Though I just learned there is a bird called Surf Scooter - gotta love that :D




The code to load the correct layout file is pretty simple.

Yeah, THAT part is easy - its the rest which is difficult :)
 
Upvote 0

markcrhome

Member
Licensed User
Longtime User
Downloaded from market to my galaxy tab 7", and the right hand of the list screen is not showing the alphabetical lettering as in the image?
It does show a fast scroll tag though

Great app by the way.

Also, what database format are you storing the data in? SQLite or plain text style, just curious!
 
Last edited:
Upvote 0

Merlot2309

Active Member
Licensed User
Longtime User
Hi again,

@ nfordbscndrd
Thanks for letting me know:

Right now I'm set up for three -- 800x480x240 (4" phones), 800x480x160 (7" tablets), 1280x800x160 (10" tablets), but before I release my app, I'll probably add one for 1024x600x170 (7" tablets) since more 7" tablets are coming out in that size.

Despite all the different sized 7" and 10" tablets, they all have a scale of 1, so Android would not make any automatic adjustments for their different sizes and number of pixels.

So, I will check/add a layout for the 7" tablet as well. Good tip!

Looking forward to see your app alive and kicking.

@Hackhack:
So I not only forced the app to portrait;) This app is not very suitable for landscape, I think. Will check the Asus Transformer as well; maybe that will change my mind.

@markcrhome:
Thanks!
Ok, have to add or change a layout for the Samsung Galaxy Tab 7".
Will let you know when it´s ready.
I use SQLite, with the Firefox plugin SQLite Manager.

---

Just finished to use as many arrays for the Views as possible. Something that I missed when I started with the app but very practical when you start with Layout Variants.

Helen.
 
Upvote 0

nfordbscndrd

Well-Known Member
Licensed User
Longtime User
Ok, have to add or change a layout for the Samsung Galaxy Tab 7".

In your code, if you are not adjusting the size and locations of views to the actual Activity.Width and .Height of devices, then you can end up with parts of views chopped off (as explained on the Wiki page), so it's not just the Galaxy Tab 7", but any device which has soft menus along either the long or short edge of the screen, for example.
 
Upvote 0

Merlot2309

Active Member
Licensed User
Longtime User
Hello,

Just uploaded a new version of the Species translator Birds on the market ( https://market.android.com/details?id=Species.Translator&feature=search_result ) and I cross my fingers that all layouts are ok now.
Cross my fingers because Samsung has a plugin for the Galaxy Tab for the AVD. The details show: 240 dens. while eg the 7" Tab has a 150 dens (at least that is what I found on Internet.

@ nfordbscndrd: thank you very much for your help.
I changed all LayoutValues. to Activity. and added some other LO Variants.

@Hackhack: I guess a plant name translator won´t be it for you either, ha, ha.

Greets,
Helen.
 
Upvote 0
Top