Android Question Application crash

ThePuiu

Active Member
Licensed User
Longtime User
Hi, I'm trying to make a simple application. From the first activity, when I press a button I want to open another Activity in which I load a layout built in the designer. This layout contains a ScrollView between 2 ImageView. I use this code:
B4X:
Sub Globals  
    Dim sw As ScrollView
    Dim lblInformation As Label
    Dim su As StringUtils
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("HowTo")
    Scale.SetReferenceLayout(480, 800, 1.5)
    Scale.ScaleAll(Activity, True)
  
    sw.Initialize(Activity.Height - 300dip) [*]

    lblInformation.Initialize("")
    sw.Panel.AddView(lblInformation, 10dip, 10dip, sw.Width - 20dip, 100dip) [**]
    lblInformation.Color = Colors.White
    lblInformation.TextColor = Colors.Black
    lblInformation.Text = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim..."

    lblInformation.Height = su.MeasureMultilineTextHeight(lblInformation, lblInformation.Text)
    sw.Panel.Height = lblInformation.Top + lblInformation.Height + 10dip     
End Sub

First question is why if ScrollView is created in designer, IDE suggests to initialize it? (first [*] sign)
And second problem: Using the above code when opening activity, the application crashed with a black screen. If I remove the code starting with the second [**] mark, the application is no longer blocked, obviously ScrollView being empty.
What I'm doing wrong? Thank you!
 

ronell

Well-Known Member
Licensed User
Longtime User
rename the scrollview in designer or add the views in code
B4X:
Activity.AddView(sw, 0, 0, 50%x, 50%y)
 
Upvote 0

ThePuiu

Active Member
Licensed User
Longtime User
My mistake ... I did not open my eyes wide enough!
Now I'm trying to add an image above the text. The image loads but is not displayed (verified in debugger). The modified code is below:

B4X:
Dim iv As ImageView
    iv.Initialize("")
    iv.Bitmap = LoadBitmap(File.DirAssets, "beaver.png")
    ScrollView1.Panel.AddView(iv, 5dip, 0dip, ScrollView1.Width, 150dip)

    lblInformation.Initialize("")
    ScrollView1.Panel.AddView(lblInformation, 5dip, 0dip, ScrollView1.Width - 10dip, ScrollView1.Height)
    lblInformation.Color = Colors.RGB(246,255,99)
    lblInformation.TextColor = Colors.Black
    lblInformation.Text = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus."
   
    lblInformation.Height = su.MeasureMultilineTextHeight(lblInformation, lblInformation.Text)
    ScrollView1.Panel.Height = lblInformation.Top + lblInformation.Height + 10dip
 
Upvote 0

ronell

Well-Known Member
Licensed User
Longtime User
you sure you have beaver.png in your assets? i test in in my device using available image in assets.. works fine
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
That's normal behaviour.
You add the ImageView on top of the ScrollView.Panel.
Then you cover it with the Label putting the ImageView behind and therefore hidden.
If you want to keep the ImageView visible you must set the background color of the Label transparent or semitransparent.
Or move the Label below the ImageView.
 
Upvote 0
Top