Android Question [Solved] once again: dip an dpi

Pflichtfeld

Active Member
Licensed User
Read a lot of dpi and dip, but am still confused:
In designer, I set lbltitle.height to 30
I can in Activity_Create set the lbltitle.height and log all that:
B4X:
    Log(LblTitle.Height)
    LblTitle.Height=30dip
    Log(LblTitle.Height)
    LblTitle.Height=30
    Log(LblTitle.Height)
    Dim ii As Int=30
    LblTitle.Height=ii
    Log(LblTitle.Height)
    'LblTitle.Height=ii dip    'of course does not work.
which gives me the values:
98
90
30
30

1. Why is the height-log first 98 and then 90? should it not be the same?
2. How can I set a dip-value with a variable.
 

klaus

Expert
Licensed User
Longtime User
You have probably AutoScaleAll in the Designer Script.

1586097314411.png


The first answer is with AutoScaleAll.
The second in dip, your device has a scale of 3.
The third and fourth values are in pixels.

Don't confuse dip density independent pixel and dpi dots per inch.
 
Upvote 0

Pflichtfeld

Active Member
Licensed User
[QUOTE="klaus, post: 724388, member: 904"
The first answer is with AutoScaleAll.
[/QUOTE]
Thank you Klaus, this was really a precious hint!! It also teaches me the principle of AutoScaleAll!
My second question should be correctly be answered by:
B4X:
LblTitle.Height=DipToCurrent(ii)
Hope that is right!
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Well, it depends on what you want to do.
You have different possibilities:
B4X:
LblTitle.Height = 30dip

Dim ii As Int=30dip
LblTitle.Height = ii

Dim ii As Int=30
LblTitle.Height= DipToCurrent(ii)
All are the same !

30dip is the shortcut of DipToCurrent(30)
 
Upvote 0
Top