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
 

Isac

Active Member
Licensed User
Longtime User
this is an example and are all written in this way

B4X:
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

lock255

Well-Known Member
Licensed User
Longtime User
Try to insert a Panel, then in the properties of btnData activities instead of assigning the panel that you created.
Finally, add this code:
B4X:
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

Isac

Active Member
Licensed User
Longtime User
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.

B4X:
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

eps

Expert
Licensed User
Longtime User
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

Isac

Active Member
Licensed User
Longtime User
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

Isac

Active Member
Licensed User
Longtime User
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

eps

Expert
Licensed User
Longtime User
I have tended to use different font sizes for different screen resolutions, something like this :

B4X:
        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

Isac

Active Member
Licensed User
Longtime User
ok but for example pScreenHeight as I declare it?
dim pScreenHeight as ImageView?
comparison ImageView with the resolution?
thanks
 
Upvote 0

eps

Expert
Licensed User
Longtime User
Int

e.g.

B4X:
pScreenHeight=GetDeviceLayoutValues.Height

But you may need to consider the width as well... depending on the device orientation.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
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

Isac

Active Member
Licensed User
Longtime User
I'm sorry, but I have to insert the resolution of my mobile phone in givensize?


B4X:
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

klaus

Expert
Licensed User
Longtime User
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

Isac

Active Member
Licensed User
Longtime User
klaus to me does not work

B4X:
    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

Isac

Active Member
Licensed User
Longtime User
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
Top