Android Question HorizontalScrollView.Panel.Width problem

Discussion in 'Android Questions' started by danijel, Mar 18, 2019.

  1. danijel

    danijel Member Licensed User

    I have a problem with horizontal HorizontalScrollView.Panel.Width atribute.
    This is a simplified example of what I want to achieve:
    First I want to show 50 labels in HorizontalScrollView.
    Then generate a random number and show to user only that many labels to choose from.
    (Choosing just mean to center that number/label)

    Problem 1:
    When random number is generated, HorizontalScrollView is not reduced immediately to that number of Labels.
    HorizontalScrollView is reduced only when User click on certain Label.

    Problem 2:
    HorizontalScrollView is resized only once. Code is not working after that at all. I want to repeat that process many times.

    Problem 3:

    If User first click on certain Label and then on 'get random number' HorizontalScrollView is never reduced. Not even once.

    Fact:
    If BTN_Click is simulated from Activity_Create then HorizontalScrollView is reduced immediately as it should after regular User Click.

    My code is below and I hope someone can clarify what is going on here :/

    Code:
    #Region  Project Attributes
        
    #ApplicationLabel: HSV Example
        
    #VersionCode: 1
        
    #VersionName: 1
        
    #SupportedOrientations: portrait
        
    #CanInstallToExternalStorage: true
    #End Region

    #Region  Activity Attributes
        
    #FullScreen: True
        
    #IncludeTitle: False   
    #End Region

    Sub Process_Globals
    End Sub

    Sub Globals
        
        
    Dim HSV As HorizontalScrollView
        
    Dim BTN As Button
        
    Dim LBL(50As Label
        
    Dim Ht As Int
        
    End Sub

    Sub Activity_Create(FirstTime As Boolean)
            
        Ht=
    100%x/9    'Label Width and Height
        HSV.Initialize(50*Ht, "HSV")
        
    Activity.AddView(HSV, 020%x100%x, Ht)
        HSV.Color=
    Colors.RGB(01510)

        
    For i=0 To 49
            LBL(i).Initialize(
    "LBL")
            HSV.Panel.AddView(LBL(i), i*Ht, 
    0, Ht, Ht)
            LBL(i).Text=i+
    1
            LBL(i).TextSize=
    20
            LBL(i).Gravity=
    Gravity.CENTER
            LBL(i).TextColor=
    Colors.White
        
    Next
        
        BTN.Initialize(
    "BTN")
        
    Activity.AddView(BTN, 10%x50%x80%x30%x)
        BTN.Text=
    "Get Random Number"
        
        
    'BTN_Click
        
    End Sub

    Sub LBL_Click
        
        
    Dim L As Label
        L=
    Sender
        
        
    For i=0 To 49
            LBL(i).Color=
    Colors.ARGB(0,0,0,0)
        
    Next
        
        L.Color=
    Colors.RGB(01910)
        HSV.ScrollPosition=L.Left+L.Width/
    2-50%x
        
    End Sub

    Sub BTN_Click
        
        
    Dim Rnd_Num As Int
        Rnd_Num=
    Rnd(10,49)
        BTN.Text=
    "Get Random Number" & CRLF & Rnd_Num
        HSV.ScrollPosition=
    0
        HSV.Panel.Width=Rnd_Num*Ht
        
    End Sub

    Sub Activity_Resume
    End Sub

    Sub Activity_Pause (UserClosed As Boolean)
    End Sub
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    This code works:
    Code:
    Sub BTN_Click
       
    Dim Rnd_Num As Int
       Rnd_Num=
    Rnd(10,49)
       BTN.Text=
    "Get Random Number" & CRLF & Rnd_Num
       HSV.ScrollToNow(
    0)
       HSV.Panel.Width=Rnd_Num*Ht
       
    Dim jo As JavaObject = HSV.Panel
       jo.RunMethod(
    "requestLayout"Null)
    End Sub
     
    danijel and BillMeyer like this.
  3. danijel

    danijel Member Licensed User

    Erel, I love You :)

    I tried something with Invalidate(), Sleep(0) and forbidden DoEvents with no success.
    RequestLayout is something in that direction (kinda).
    Can you point me on some lesson to better understand what went wrong in my code?

    Thx again <3
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    Your code is correct. This seems like an issue with the native ScrollView and HorizontalScrollView controls.
     
    danijel likes this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice