Android Question ScrollView doesn't scroll

GaNdAlF89

Active Member
Licensed User
Hi!! I have this code in Activity_Create sub:

There is a label on a Scrollview (which is on a main panel)
B4X:
   PanelDescrizione.Initialize("PanelMain")
   PanelDescrizione.Enabled = True
   PanelDescrizione.Visible = True

   #Region ScrollViewTesto
   ScrollViewTesto.Initialize(60%y)
   ScrollViewTesto.Enabled = True
   ScrollViewTesto.Visible = True
 
   #Region LabelTesto
   LabelTesto.Initialize("LabelTesto")
   LabelTesto.Enabled = True
   LabelTesto.Visible = True
   LabelTesto.Text = STR2
   LabelTesto.TextColor = Colors.Black
   LabelTesto.Gravity = Bit.Or(Gravity.TOP,Gravity.CENTER_HORIZONTAL)
   LabelTesto.TextSize = 22
 
   ScrollViewTesto.Panel.AddView(LabelTesto,0,0,94%x,60%y)
   #End Region
 
   PanelDescrizione.AddView(ScrollViewTesto,3%x,15%y,94%x,60%y)
   #End Region
 
   Activity.AddView(PanelDescrizione,0,0,100%x,100%y)
STR2 is partly visible but the scroll function doesn't work

Where is the problem? Thanks!
 

derez

Expert
Licensed User
The height in the scrollview initialization which is the size of the scrollview's panel can be greater then the size of the view itself. If is not - the panel will not scroll.
So, change
ScrollViewTesto.Initialize(60%y) to
ScrollViewTesto.Initialize(200%y)
and see if it scrolls.
 

GaNdAlF89

Active Member
Licensed User
Ok it works, but my problem is the height of label depending on his text lenght. How can I do?
 

GaNdAlF89

Active Member
Licensed User
Thanks for all!! :)
I've solved with adding this:
B4X:
Dim suTmp As StringUtils
LabelTesto.Height = suTmp.MeasureMultilineTextHeight(LabelTesto,STR2)
ScrollViewTesto.Panel.Height = LabelTesto.Height
 
Top