Android Question ScrollPosition Not Work

Artur Martins

Member
Licensed User
Longtime User
scrollPosition does not work in the following code:

B4X:
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:

Cableguy

Expert
Licensed User
Longtime 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.
 
Upvote 0

Artur Martins

Member
Licensed User
Longtime 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
 
Upvote 0

Artur Martins

Member
Licensed User
Longtime 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.
 
Upvote 0

Artur Martins

Member
Licensed User
Longtime User
I can not upload my project in .zip, then follow the code source of the project:
B4X:
#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.
 
Upvote 0

klaus

Expert
Licensed User
Longtime 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.
 

Attachments

  • ScrollToNow.zip
    11.4 KB · Views: 227
  • ScrollToNowNew.zip
    11.5 KB · Views: 280
Last edited:
Upvote 0
Top