Too many Android screen sizes

rfresh

Well-Known Member
Licensed User
Longtime User
I've made a list of some of the Android screen sizes that I could find on the internet and came to the conclusion there too many to specifically code for. The 480x800 resolution (for example) isn't so bad but when you throw in the DPI/PPI values, then it becomes unmanageable in my opinion.

I'm positioning my UI components on the screen based on %. For example, my title Label is position 0.05% down and centered on the screen. Regardless of the screen size, the title label will always be positioned that way.

The problem is that I've created some basic Emulators using the standard 160 or 240 DPI so I can run a test cycle and figure out exact placement for about 7 Emulators. But the list I've put together shows a lot of other DPI's (I have 67 devices on my list and I'm attaching it for anyone who wants it) and I'm wondering if using dips will allow my % positioning that I've fine tuned for 160 and for 240 to work with those other dips?
 

Attachments

  • ScreenResolutions.zip
    6.3 KB · Views: 406

rfresh

Well-Known Member
Licensed User
Longtime User
It is very hard to tell from the pictures as they do not preserve the original scale.

See this thread for more information about the next version: http://www.b4x.com/forum/basic4android-updates-questions/15797-java-runtime-jdk.html

What would you suggest I do, just put my project on hold and wait?

I feel my project is stuck and that I can't move forward because the code I've posted with the dip's produces different screen displays for 160 DPI and 320 DPI. No one has suggested or recommended what I could try to fix this.

I'm stuck but you're recommending that I wait 2 weeks until you next beta version is released? I don't think my problem will go away with that new ver based on what you've said. I think my problem is that I'm having a hard time wrapping my head around using dips to scale buttons and labels, etc. on a variety of displays.

I'm not a b4a coding veteran. I'm new to it so I've come to this forum for some help and I've always received help. It's one of the very nice things about programming in b4a, the support in this forum. But I feel this post has run out of steam and I'm still stuck on how to move forward.

But in any event, I was hoping to get my small test app working on the 4 DPI's of the 320x480 screen so I can apply it to my real project. Jose suggested I start out small to learn about this topic and I've done that with my small test app which I've zipped up and attached in this thread. I know the thread has run out of steam but I would really appreciate more suggestions on what else I might be able to try (if anything).

@Erel is the emulator 100% like the device its simulating? Maybe the off scale that I see in the x320 DPI doesn't really look like that on a real device with that resolution and DPI?

Perhaps someone else can just tell me if my small test code looks right in how I'm handling the dip's at the end of each line? Maybe that's all I can do with the code?

Thank you again everyone...
 
Upvote 0

rfresh

Well-Known Member
Licensed User
Longtime User
Yes I can post that but I'd like to understand the small little test app I created with just a button and a Label. If I can get that to work and understand how it works then I can apply it to my main project.

I'm attaching one image showing the results of all 4 emulators that I have to support 320x480 for each DPI, x120, x160, x240 and x340. I ran each emulator in actual size. To me, it looks like my dip code isn't working (see my small test code above in this thread), however, as I have stated several times, I am new to this and maybe, to you Erel, they look ok and my dip code is ok and working as it should. But I don't think so.

I think if we can get my test app to work right, then I can apply those same changes to my main project and it will work right to.

Is there a way I can also upload my 4 emulators?

Thank you very much for your help and support...
 

Attachments

  • 320x480_4_Emulators.jpg
    320x480_4_Emulators.jpg
    30.6 KB · Views: 299
Last edited:
Upvote 0

DarkMann

Member
Licensed User
Longtime User
Hi,

I think that part of your difficulty is that real devices don't come in all those dpi sizes for a given screen. What I mean is that a 320x480 screen is, by definition a small one and would have a scale of 1 (160dpi) every time.

320x480 scale 1 (Probably a 3-inch screen)
480x800 scale 1.5 (probably a 4-inch screen but some 7-inch tablets are scale=1)
600x1024 scale 1 (older 10-inch tablets)
800x1280 scale 1.5 or 2 (newer tablets - fancy phones are where scale=3 comes in)

Your emulators need to follow the sizes and scales of the standard devices and then you will see that it all mostly works out fine using dip or %x and %y.

Your screenshots are using the same pixel dimensions and what I see makes sense. The bigger the dpi or scale, the bigger the views appear.

In the real world, text is bigger on a bigger screen if you use DIP, but that's what one expects. The alternative is to have the text and views stay small, but cram loads more info into the space available.

Hope that helps,

David
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
As DarkMann wrote there are no such devices and it is possible that the emulator does not behave correctly if you are creating an emulator with unrealistic values.

If you set the width of a view to 160dip on a 320x480 screen you expect it to always take up half the screen size regardless of density/scale.
This is not correct. It should have the same (more or less) physical size. As most phones have a similar physical size then a single layout should work quite good on all standard phones, regardless of their scale.

When someone writes the resolution without the scale (or dpi) then the values are completely meaningless.

I strongly recommend you to create only three variants: phone, 7'' tablet and 10'' tablet. All of them with a scale of 1.0. If you want to support both orientations then you should add another 3 variants.

Note that a device with the following values: 320x480 scale=2.0 (dpi=320) is equivalent to:
160x240, scale=1.0. This means that the device size is 1.8 inch - there is no such device.

I know that scales can be quite confusing. The truth is that you do not need to deal with it at all.
Just use 'dip' units and the layout will be scaled correctly.
 
Upvote 0

DouglasR

Member
Licensed User
Longtime User
Dibs and Variables

By using the 'dip' unit you handle the different scales in a simple way.
For example the following code will set the button physical width to be the same on all devices:
B4X:
Button1.Width = 100dip

The same is true for layouts created with the designer.

Every example of dip usage I've seen uses static numbers (e.g.: "100dip"). what about varaibles? I don't think 'button.widthdip' will work...will it?
 
Last edited:
Upvote 0

NJDude

Expert
Licensed User
Longtime User
Every example of dip usage I've seen uses static numbers (e.g.: "100dip"). what about varaibles? I don't think 'button.widthdip' will work...will it?

You can save DIP values in variables like this:
B4X:
myWidth = 100 * 1dip 'Multiplying by 1dip converts the value to dip

Button1.Width = myWidth
 
Upvote 0

DouglasR

Member
Licensed User
Longtime User
Variables with Dips - Thank you!

There is a problem with using 1dip (I also posted such a solution in the past...). To avoid rounding errors you should use 100dip / 100.

Wow! Thanks, guys! this is sooo valuable! I've been working with Basic4Android for a while now and have used the forums quite extensively and successfuly. This was my first post and got the perfect answer right away! I'm glad I actually bought the thing! Best money spent _ever_!:sign0098:

So this is what it should look like...

myWidth = 100 * (100dip / 100)

Ummm what do I declare the variable as?

Dim myWidth as Dip?

On another topic, can you provide a link to a good example of using a 'List' as a replacement for ReDim?
 
Last edited:
Upvote 0

lagore

Active Member
Licensed User
Longtime User
I believe myWidth should be an int.

Sent from my HTC One X using Tapatalk 2
 
Upvote 0
Top