Android Question ScrollPosition Not Work

Discussion in 'Android Questions' started by Artur Martins, Mar 2, 2015.

  1. Artur Martins

    Artur Martins Member Licensed User

    scrollPosition does not work in the following code:

    Code:
    Sub IME_HeightChanged (NewHeight As Int, OldHeight As Int)
        
    Dim rol_scrol As Int
     
        
    If NewHeight = 100%y Then
            scroll.Panel.Height = 
    81%y + 100%y - NewHeight
        
    Else
            scroll.Panel.Height = 
    71%y + 100%y - NewHeight
        
    End If
     
        rol_scrol = posicao_tela - NewHeight
     
        scroll.ScrollPosition = rol_scrol

    End Sub
    Why?
     
    Last edited: Mar 2, 2015
  2. Cableguy

    Cableguy Expert Licensed User

    Olá Artur

    Já tentaste fazer Log(rol_Scrol) para saber qual o valor que lhe esta a ser atribuido?
    Onde vais buscar o valor 'posicao_tela'?
    Apenas com essa sub nao podemos saber exactamente o que se passa pois estas a usar variaveis que nao sabemos a sua origem.

    Hi Artur

    Have you tried logging rol_scrol to see its value?
    Where do you get 'posicao_tela' value?
    With only this sub it's hard to tell where the error lies as you use vars that we don't know their origin.
     
  3. Artur Martins

    Artur Martins Member Licensed User

    hello cableguy

    in a test with logs

    rol_scrol the value is 131

    after that the scroll.scrollposition value continued to 0 o_O
     
  4. klaus

    klaus Expert Licensed User

    What exactly doesn't work ?
    I don't understand why you change the height of internal panel of the scrollview ?
     
    KMatle likes this.
  5. Artur Martins

    Artur Martins Member Licensed User

    hello Klaus

    In this case my scroll bar remains in the same position after the command scrollPosition.

    The Intent of this code is to create a scroll bar at the time the keyboard is turned on, so I can roll this bar and view other views.
     
  6. klaus

    klaus Expert Licensed User

    Try to add a DoEvents after scroll.ScrollPosition = rol_scrol.
     
  7. Erel

    Erel Administrator Staff Member Licensed User

    It is better to use ScrollToNow and avoid the DoEvents call.
     
  8. klaus

    klaus Expert Licensed User

    In the clsWheel class I even needed this to ensure the scrolling:
    Code:
    scvWheel(i).ScrollToNow(ScrollPos(i))
    DoEvents
    scvWheel(i).ScrollToNow(ScrollPos(i))
    DoEvents
     
  9. Artur Martins

    Artur Martins Member Licensed User

    DoEvents and ScrollToNow not work :(
     
  10. klaus

    klaus Expert Licensed User

    I'm afraid that we are turning in circle.
    You should post a small project showing the problem so we could see what you have done and how and test it.
     
  11. Artur Martins

    Artur Martins Member Licensed User

    ok I will summarize my project and probably tomorrow will be posting here to continue the discussion

    Thanks
     
  12. Artur Martins

    Artur Martins Member Licensed User

    I can not upload my project in .zip, then follow the code source of the project:
    Code:
    #Region  Project Attributes 
        
    #ApplicationLabel: B4A Example
        
    #VersionCode: 1
        
    #VersionName
        
    'SupportedOrientations possible values: unspecified, landscape or portrait.
        #SupportedOrientations: unspecified
        
    #CanInstallToExternalStorage: False
    #End Region

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

    Sub Process_Globals
        
    'These global variables will be declared once when the application starts.
        'These variables can be accessed from all modules.

    End Sub

    Sub Globals
        
    Dim painel As Panel
        
    Dim et_descricao As EditText
        
    Dim tv_fabric As Label
        
    Dim IME As IME
        
    Dim scroll As ScrollView
        
    Dim posicao_tela As Int
       
    End Sub

    Sub Activity_Create(FirstTime As Boolean)

        
    Activity.Color = Colors.RGB(255,112,67)
       
        
    IME.Initialize("IME")
        
    IME.AddHeightChangedEvent
       
        scroll.Initialize2(
    81%y,"scroll")
       
        painel.Initialize(
    "painel")
        painel.Color = 
    Colors.White
       
       
        et_descricao.Initialize(
    "et_descricao")
        et_descricao.Hint = 
    "Descrição"
        et_descricao.ForceDoneButton = 
    True
        et_descricao.SingleLine = 
    True
       
       
        tv_fabric.Initialize(
    "tv_fabric")
        tv_fabric.Text = 
    "Cadastro de fornecedor"
        tv_fabric.Gravity = 
    Gravity.CENTER
        tv_fabric.TextSize = 
    20
        tv_fabric.Typeface = 
    Typeface.CreateNew(Typeface.MONOSPACE,Typeface.STYLE_BOLD)
       
        painel.AddView(et_descricao,
    1%x,70%y,98%x,75)
       
        
    Activity.AddView(tv_fabric,0,0,100%x,9%y)
        
    Activity.AddView(scroll,0,9%y,100%x,81%y)
        scroll.Panel.AddView(painel,
    0,0,100%x,81%y)
           
    End Sub

    Sub IME_HeightChanged (NewHeight As Int, OldHeight As Int)
        
    Dim rol_scrol As Int
       
        
    If NewHeight = 100%y Then
            scroll.Panel.Height = 
    81%y + 100%y - NewHeight
        
    Else
            scroll.Panel.Height = 
    71%y + 100%y - NewHeight
        
    End If
               
        rol_scrol = posicao_tela - (NewHeight - 
    9%y)
       
        scroll.ScrollToNow(rol_scrol)

    End Sub

    Sub et_descricao_FocusChanged (HasFocus As Boolean)
        
    If HasFocus Then
            posicao_tela = et_descricao.Top + et_descricao.Height
        
    End If
    End Sub

    Sub Activity_Resume
       
    End Sub


    Sub Activity_Pause (UserClosed As Boolean)
       
    End Sub
    sorry for the delay, now I lack time.
     
  13. klaus

    klaus Expert Licensed User

    Why can't you post the project ?
    To export the project, as a zip file, use the IDE menu File / Export As Zip and then upload the zip file to the post.

    For the height of et_descricao you should use 75dip instead of 75.

    There seems to be a problem with scroll position change after a ScrollView.Panel.Heigt change.
    Erel, you should have a look at the attached project, it's a modifyed version of the code in post#12.

    EDIT: 2012.03.08 Added a modified version after Erels answer.
     

    Attached Files:

    Last edited: Mar 8, 2015
    Cableguy likes this.
  14. Erel

    Erel Administrator Staff Member Licensed User

    I've changed CallSub2 to CallSubDelayed2 and it seems to solve this issue. The ScrollView new height is not immediately gets updated. It needs to handle the message queue first.
     
    klaus likes this.
  15. klaus

    klaus Expert Licensed User

    Thank you Erel.
    The frustrating thing for me is that I was thinking CallSubDelayed2 but put CallSub2 in the code.
     
    Erel likes this.
  16. Artur Martins

    Artur Martins Member Licensed User

    worked perfectly, Thanks to all :)
     
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