Java Question Question about B4A Activity contentView

thedesolatesoul

Expert
Licensed User
Longtime User
This is not a very important question but neverthless.
While trying to port Tooleap library which makes an Activity into a sidebar. When it does this is shrinks the Activity's contentView. All the views are relative to this, so they all scale accordingly.

While using B4A, when creating a label (in code), I can set it to Activity.Width or 100%x (and gravity to centre), but the label text is not in the centre, of the activity, but it is in the centre of the screen.

Is the B4A Activity contentView positioning everything according to the screen width rather than the activity's contentView?

(I dont even understand this fully, so any hints and tips would be great).
 

thedesolatesoul

Expert
Licensed User
Longtime User
It seems to be.

But atleast this code is not giving me the correct values.

B4X:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Private ActivityParent As JavaObject
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")
   
  Dim jo As JavaObject = Activity
  jo.RunMethodJO("getContext", Null).RunMethodJO("getWindow", Null).RunMethod("setSoftInputMode", _
    Array As Object(0x20))
  ActivityParent = jo.RunMethodJO("getParent", Null)

  Dim ajo As Panel = Activity
  Dim width As Int = ActivityParent.RunMethod("getMeasuredWidth", Null)
  Dim height As Int = ActivityParent.RunMethod("getMeasuredHeight", Null)
  'If width = 0 OR height = 0 Then Return
  ajo.width = width 'update the "activity" width and height
  ajo.height = height
   
    Dim lbl As Label
    lbl.Initialize("")
    Activity.AddView(lbl, 0, 0, Activity.Width, Activity.Height)
    lbl.Gravity = Gravity.CENTER_HORIZONTAL + Gravity.CENTER_VERTICAL
   
    Dim TA As MSTooleapActivityHelper

    If TA.isStartedByTooleap Then
        lbl.Text = "Started by Tooleap"
    Else
        lbl.Text = "Started in normal mode"
    End If

End Sub
 
Top