Android Question The size and position with setlayout

Isac

Active Member
Licensed User
Longtime User
Hello,
I changed the position of the buttons with setLayout () on the cell S3,
but when I load the same program on a cellualre with lower resolutions, the buttons remain the same size, but the text inside the buttons is almost canceled.
Do you have any idea?

thanks
 
this is an example and are all written in this way

Code: Copy
Sub Activity_Create(FirstTime As Boolean)
   
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("mio")
    btnData.SetLayout(10%x,20%y,20%x,10%y)

How do I set the DIP?
 
Upvote 0
Try to insert a Panel, then in the properties of btnData activities instead of assigning the panel that you created.
Finally, add this code:
Code: Copy
Sub Activity_Create(FirstTime As Boolean)

    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("mio")
    pnlMain.SetLayout(0%x,0%y,100%x,100%y)
    btnData.SetLayout(10%x,20%y,20%x,10%y)
 
Last edited:
Upvote 0
If I place the buttons referring to cell s3 and then I transfer the program on a galaxy next I see the smaller buttons with the words not whole
How do I maintain this proportion for all phones.

Code: Copy
Sub Activity_Create(FirstTime As Boolean)
  
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("mio")
   
    Label1.SetLayout(18%x,12%y,45%x,10%y)
    Label2.SetLayout(57%x,16%y,45%x,7%y)
    btnData.SetLayout(55%x,25%y,45%x,7%y)
    ImgStorico.SetLayout(55%x,3%y,45%x,7%y)
    btnAvvisami.SetLayout(0%x,73%y,100%x,9%y)
    btnCancella.SetLayout(0%x,85%y,100%x,9%y)
    ImageView3.SetLayout(27%x,48%y,45%x,7%y)
    edGiorni.SetLayout(71%x,48%y,30%x,7%y)
 
Upvote 0
There is autoscale in the Designer or you need to programmatically work this out. Font sizes aren't DIP, but do get adjusted... but not as well as they could be.
 
Upvote 0
I tried to use as a reference the galaxy next and then I loaded everything on the phone s3 so I have no problems

but I do not understand why
 
Upvote 0
The buttons are sized correctly, but the lettering on the buttons no
maybe I should not use setLayout but leave it in autoscale?
but then the position will be maintained?
 
Last edited:
Upvote 0
I have tended to use different font sizes for different screen resolutions, something like this :

Code: Copy
        If pScreenHeight > 800 Then
            lbltopright.TextSize = 24
        Else If pScreenHeight > 500 Then
            lbltopright.TextSize = 22
        Else
            lbltopright.TextSize = 20
        EndIf

It's not pretty, but does the job - of course it depends if all your text has the same size, etc... and how much of it there is.
 
Upvote 0
ok but for example pScreenHeight as I declare it?
dim pScreenHeight as ImageView?
comparison ImageView with the resolution?
thanks
 
Upvote 0
Int

e.g.

Code: Copy
pScreenHeight=GetDeviceLayoutValues.Height

But you may need to consider the width as well... depending on the device orientation.
 
Upvote 0
You could use
TextScale = GetDeviceLayoutValues.ApproximateScreenSize / GivenSize
and
lbltopright.TextSize = 24 * TextScale
GivenSize is the device size for the 24 TextSize.
Example: if TextSize = 24 is for a 10'' device then
TextScale = GetDeviceLayoutValues.ApproximateScreenSize / 10
 
  • Like
Reactions: eps
Upvote 0
I'm sorry, but I have to insert the resolution of my mobile phone in givensize?


Code: Copy
Dim TextScale As Int
Dim lbltopright As  EditText
Dim Textsize As Int

Sub Activity_Create(FirstTime AsBoolean)


'Do not forget to load the layout file created with the visual designer. For example:

Activity.LoadLayout("mio")

lbltopright.Initialize(lbltopright)

TextScale = GetDeviceLayoutValues.ApproximateScreenSize / 1000    

lbltopright.Textsize = 24 * TextScale           
If Textsize = 24 Then

TextScale = GetDeviceLayoutValues.ApproximateScreenSize / 24

EndIf

What's wrong?

thanks for your attention
 
Upvote 0
What is the screen size in inches of the screen where TextSize = 24 ?
If you want TextSize = 24 on a 10'' screen then
TextScale = GetDeviceLayoutValues.ApproximateScreenSize / 10
If you want TextSize = 24 on a 7'' screen then
TextScale = GetDeviceLayoutValues.ApproximateScreenSize / 7
If you want TextSize = 24 on a 5'' screen then
TextScale = GetDeviceLayoutValues.ApproximateScreenSize / 5
And so on !
Then
lbltopright.Textsize = 24 * TextScale
and nothing else !
The advantage using ApproximateScreenSize is that you don't need to take care of the screen resolution nor any dip value !
 
Upvote 0
klaus to me does not work

Code: Copy
    Dim TextScale As Int
    Dim lbltopright As EditText
    Dim Textsize As Int

End Sub

Sub Activity_Create(FirstTime As Boolean)
   
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("mio")
    lbltopright.Initialize(lbltopright)
   
    TextScale = GetDeviceLayoutValues.ApproximateScreenSize / 5
    lbltopright.Textsize = 24 * TextScale

    Label1.SetLayout(18%x,12%y,45%x,10%y)
    Label2.SetLayout(57%x,16%y,45%x,7%y)
    btnData.SetLayout(55%x,25%y,45%x,7%y)
    ImgStorico.SetLayout(55%x,3%y,45%x,7%y)
    btnAvvisami.SetLayout(0%x,73%y,100%x,9%y)
    btnCancella.SetLayout(0%x,85%y,100%x,9%y)
    ImageView3.SetLayout(27%x,48%y,45%x,7%y)
    edGiorni.SetLayout(71%x,48%y,30%x,7%y)
 
Upvote 0
the text above the buttons is bigger and I see him in half.
Nothing has changed.
is just as I wrote the source?
 
Upvote 0
Back
Top