Screen Density, dip, and resizing?

DevBaby

Active Member
Licensed User
Longtime User
The views I created in the designer have location dimension in pixels only, not dip. For example Top = 80 as opposed to Top = 80dip. My layout has 160 density, Scale = 1. In short, I did not think this mattered in the designer, although I did read to use dip in a coding example.

Ultimately, when testing on a device with higher density than 160, my views automatically resized by a factor of 1.5 and no longer fit on the screen. As a quick fix, I believe I can read the device’s density and run a loop through each view and reset their size according to the density factor (1.5).

Does every Android device have a standard density (160, 240, 320 etc) that will result in a .75 or 1.5, or 2 scale factor?

I can, though painfully, go back into the designer and edit each position item to dip. But if I can fix this through code to reverse the scaling, I would much rather do this in code if I am guaranteed that every device will have 1 of the 4 density values I have read about. If there are many different density values (149, 172 etc) and scaling factors, then I would most likely have to edit each view in my designer layout.

Is there a way to edit the bal file to quickly make this adjustment for dip?
 

NJDude

Expert
Licensed User
Longtime User
The .bal file is where the layout is saved, you cannot edit that since is not a "text" file.

You will have to manually add "dip" to your source, and by the way, you MUST use dip to position views that way they will scale properly on any device.
 
Upvote 0

DevBaby

Active Member
Licensed User
Longtime User
Thanks NJDude,

Why did my views scale anyway given that I did not use dip values in the designer? That is where I am having my problem.

I have a rescaling routine that I developed myself to resize for different size screens. This code has worked fine for every device until I tested one that had a density value greater than the 160 in my layout; then the values that I set in the designer (let’s say 80) automatically became 120 when the program loaded on the device with the higher density value.

I actually do not want my views to automatically resize because I prefer to handle different screen sizes in code based on the original layout I set in the designer.
 
Upvote 0
Top