Android Question Activity AddView

MarcoRome

Expert
Licensed User
Longtime User
Hi all, i have this simple code:

B4X:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim segna_punti As Label
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("Layout1")
            segna_punti.Initialize("")
            segna_punti.Gravity = Bit.Or(Gravity.CENTER_VERTICAL, Gravity.CENTER_HORIZONTAL)
            Dim c2 As ColorDrawable
            c2.Initialize2(Colors.ARGB(255, 248, 0, 0),10dip,3dip,Colors.Black)
            segna_punti.Background = c2
            segna_punti.Text = "INDICE DI VENDIBILITA 0%"
            segna_punti.TextSize = 16
            segna_punti.Typeface = Typeface.DEFAULT_BOLD
            segna_punti.TextColor = Colors.Black
         
            Activity.AddView(segna_punti, 0, 70%y, 100%x, 100%y )



End Sub

Now i wait that this
Activity.AddView(segna_punti, 0, 70%y, 100%x, 100%y )
give me this result:

2016-01-07 07.34.48.png


and instead gives me this result:

2016-01-07 07.32.52.png


I have correct result if i write this:
Activity.AddView(segna_punti, 0, 70%y, 100%x, 30%y )
It has anything changed ??

Thanks
Marco
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
The last parameter is the view's height. If you set it to 100%y then its height will be the same as the activity height. Which will of course extend out of the visible screen.

I think that you are confusing Activity.AddView with the SetTopAndBottom method in the designer script.

The best way is to add the view with the designer and set its vertical anchor to BOTH.
 
Upvote 0

MarcoRome

Expert
Licensed User
Longtime User
:confused: Yes i'm confusing with SetTopAndBottom.
Maybe i need again holiday :D
Thank you Erel and sorry...happen
 
Upvote 0
Top