Android Question Preventing DIP Scaling in Code

andrewj

Active Member
Licensed User
Longtime User
Hi,
I have created my views almost entirely in code, and have used dip almost everywhere. However when I run my app on a smaller device all the views are too large. I actually want to scale them to be smaller on the smaller devices.

Is there any way to set something globally so that the code scales all dip values differently?
Thanks
Andrew
 

eps

Expert
Licensed User
Longtime User
Really? This shouldn't be happening.

Have you used 100%x and 100%y ? These should make the Views the correct size and then you use DIP for items in the View or a combination of those and %x and %y where appropriate.
 
Upvote 0

andrewj

Active Member
Licensed User
Longtime User
Hi,
For example, I have set up several dialogs with sizes of ~400dip. These display fine on my Galaxy Note 10.1" (my primary test device). However on my Galaxy Note 2 (which has a 5" screen) they display too large to fit on the screen. If I had just used actual pixels they would be fine...

How am I supposed to deal with this without changing everything to %x and %y instead of dip?

Thanks
Andrew
 
Upvote 0

eps

Expert
Licensed User
Longtime User
You should use a combination of the two, where applicable.

i.e. Main View and Activity 100%x and 100%y

Smaller views percentages of those. .e.g. 2x 50%x 100%y for instance.

I'm afraid I can't see any easy way round this, but if you work top down, then some of the smaller elements will adjust, but ideally 100% is the way to go, then it just 'works' on all screens.

Have you seen this? http://www.b4x.com/android/forum/threads/supporting-multiple-screens-tips-and-best-practices.17647/

** Actually you might be able to use AutoScale in the designer, which might save you a lot of extra work, or have you already employed that?

It depends on what elements make up your App. Mine are primarily ListView / ScrollView based. I suspect yours aren't, so you'll require a slightly different approach.
 
Upvote 0

andrewj

Active Member
Licensed User
Longtime User
Hi,
I have not used the designer very much at all, as most of my views are very complex and adjust themselves depending on user actions.

The problem is with the smaller elements, which I have specified using dip not a %x or %x. Does this mean I have to change my whole code to use that form instead? Surely there's some way of setting how dip works globally?

Thanks
Andrew
 
Upvote 0

eps

Expert
Licensed User
Longtime User
But DIP is Device Independent Pixels..

If you've defined something as 500DIP wide but your device has a screen 320 pixels wide and pixel density of 1, you've nowhere to go.

It's better to work from small screens to larger ones.

If you don't use the Designer, and I don't either. Then %x and %y would seem to be the way to go..

Maybe Erel or someone else can offer another solution, but I don't know of one myself, sorry.
 
Upvote 0
Top