Android Tutorial ScrollView examples summary

Cableguy

Expert
Licensed User
Longtime User
Animating Text on a Scrollview

Hi Klaus...

Been going through your tutorials...always helpfull...

I am playing with a ScrollView wich only "child" is a label...
This label text is "animated" through a Timer, in wich Tick event, the Text is incremented by one character, thus resulting a "Left-to-Right Rolling" effect...
This is no problem, but I also wanted to be able to change the Text String and have the Labels Height and ScrollView Panel's Height automatically changed as the text was rolling...

This is my sub as it is...
B4X:
Sub TextAnim_Tick
   'Animação de texto
   If Label1.Text.Length <> ScrollText.Length Then
      Label1.Text = ScrollText.SubString2(0,Label1.Text.Length+1)
      DoEvents
      Height = Reflect.RunMethod("getHeight")
      DoEvents
      ScrollView1.Panel.Height = Label1.Top + Height + 10dip
      Label1.Height = Label1.Top + Height
      DoEvents
      If ScrollView1.Panel.Width=ScrollView1.Width OR ScrollView1.Panel.Width=-1 Then
         ScrollView1.Panel.Width=ScrollView1.Width-1
      Else
         ScrollView1.Panel.Width=ScrollView1.Width
      End If
   Else
      TextAnim.Enabled=False
      Label1.Enabled = True
   End If
End Sub

Target is Label1

The panel seems to indeed resize, but not to the entire string height, and the label seems to just not get the complete document, as it "ends" one or two lines below the visible portion of the ScrollView's Panel..

Were am I going wrong??
 
Last edited:

Cableguy

Expert
Licensed User
Longtime User
Hi Klaus...

Here's the current Zip file...

Hope it is clear to you...
 

Cableguy

Expert
Licensed User
Longtime User
Hi Klaus...once more...:sign0161:

I've updated my sub according to your updated example and it works great...

I have one request : Is it possible to make the "newly writen" text always visible? That is to say, how can I adjust scrollview scroll position acordint to the "last writen line"....??? I think I just answered the how...but i can't get to put it into code... HELP!?

EDIT :

Just answering my own question....got it to work...
This is the complete new sub:
B4X:
Sub TextAnim_Tick
   'Animação de texto
   If Label1.Text.Length <> TextLenght Then
      Label1.Text = ScrollText.SubString2(0,Label1.Text.Length+1)
      DoEvents      ' needed to update the value
      Height = StrUtils.MeasureMultilineTextHeight(Label1, Label1.Text)
   DoEvents      ' needed to update the value
   ScrollView1.Panel.Height = Label1.Top + Height + 10dip
   Label1.Height = Label1.Top + Height
   'Log(Height & "/" & StrUtils.MeasureMultilineTextHeight(lblHelp3, txt3))
   
   ' needed to update the height
   If ScrollView1.Panel.Width = ScrollView1.Width OR ScrollView1.Panel.Width = -1 Then
      ScrollView1.Panel.Width = ScrollView1.Width - 1
   Else
      ScrollView1.Panel.Width=ScrollView1.Width 
   End If
   ScrollView1.ScrollPosition = Height 'updates the scroll position to make the last text visibe
   Else
      TextAnim.Enabled = False
      Label1.Enabled = True
   End If
End Sub
 
Last edited:

klaus

Expert
Licensed User
Longtime User
Hi Paulo,
I'd suggest you following code:
B4X:
Sub TextAnim_Tick
    Dim txt As String
    
    'Animação de texto
    If Label1.Text.Length <> TextLenght Then
    
        txt = ScrollText.SubString2(0, Label1.Text.Length + 1)
        Height = StrUtils.MeasureMultilineTextHeight(Label1, txt)
        Label1.Height = Height
        Label1.Text = txt
        ScrollView1.Panel.Height = Height + 10dip
        ScrollView1.ScrollPosition = Height - ScrollView1.Height

        If ScrollView1.Panel.Width=ScrollView1.Width OR ScrollView1.Panel.Width=-1 Then
            ScrollView1.Panel.Width=ScrollView1.Width-1
        Else
            ScrollView1.Panel.Width=ScrollView1.Width
        End If
    Else
        TextAnim.Enabled = False
        Label1.Enabled = True
    End If
End Sub
In the attached zip file I added a line, in Activity_Create, to adjust the height of ScrollView1 to the screen height.
With a 320 / 480 screen ScrollView1 is too high.
I needed to comment the line with the TypeFace and added a text file, because those weren't in your zip file.

Best regards.
 

Cableguy

Expert
Licensed User
Longtime User
Thanks for the time and the response, Klaus...

Has you can see, I have managed to achieve my goal, and my code is very similar to yours...

Thanks again !!!
 

ChrShe

Member
Licensed User
Longtime User
Would there happen to be any examples for building a scrollview similar to the one used for the photo gallery? (See attached)
 

Attachments

  • scrollview.jpg
    24.7 KB · Views: 730

askez

Member
Licensed User
Longtime User
FFT Demo

hi,
i've implemented the FFT Demo and it works fine
i have one problem- every time my phone's screen shut down (15/30 sec) when i bring it back all the text goes down one line i've installled the example and it happens there too.
any solution?
thanx!
 

klaus

Expert
Licensed User
Longtime User
The program you are speeking of is the HelpScrollView example and not the FFT Demo that is part of the FFT library.
The HelpScrollView program is 'only' the help part of the FFT Demo program and uses its help files.

In the HelpScrollView program just remove
line 52 lblHelp1.Top = lblHelp2.Top

Best regards.
 

cbal03

Member
Licensed User
Longtime User
Very nice examples. Thank you so much!
 

miguelconde

Member
Licensed User
Longtime User
Hi Erel, guys.
About the removeview. It remove all the childs from the object removed?. I give you more detail about my case. I have a scrollview whit a horizontalscroolview like it child, in the horizontalscrollview i added a panel and finally two views at this panel, graphically something like this. scrollview-horzontalview-panel-2 view(chkbox and lable).When I removed the panel its children (label and chekbox) were not removed, I had to remove the children and then you can remove the panel, i solved the problem whit this algorithm. I hope I explained well.

horizontalview = ScrollView1.Panel.GetView(0)
For ic =horizontalview.Panel.NumberOfViews -1 To 0 Step -1
'remove the child
panel = horizontalview.Panel.GetView(0)
For ic2 = panel.NumberOfViews -1 To 0 Step -1
panel.GetView(0).RemoveView
Next
'then i can removed the panel inside the horizontalview
horizontalview.panel.GetView(0).RemoveView
Next

if i remove only the panel inside horizontalview whit this: horizontalview.panel.GetView(0).RemoveView
the children remain initialized, This code dont worked fine.

I hope understand my english


horizontalpanel = ScrollView1.Panel.GetView(0)
For ic = horizontalpanel.Panel.NumberOfViews -1 To 0 Step -1
'Dont removeed the child
horizontalpanel.panel.GetView(0).RemoveView
Next
 

miguelconde

Member
Licensed User
Longtime User
Hi Erel, guys.
About the removeview. It remove all the childs from the object removed?. I give you more detail about my case. I have a scrollview whit a horizontalscroolview like it child, in the horizontalscrollview i added a panel and finally two views at this panel, graphically something like this. scrollview-horzontalview-panel-2 view(chkbox and lable).When I removed the panel its children (label and chekbox) were not removed, I had to remove the children and then you can remove the panel, i solved the problem whit this algorithm. I hope I explained well.

horizontalview = ScrollView1.Panel.GetView(0)
For ic =horizontalview.Panel.NumberOfViews -1 To 0 Step -1
'remove the child
panel = horizontalview.Panel.GetView(0)
For ic2 = panel.NumberOfViews -1 To 0 Step -1
panel.GetView(0).RemoveView
Next
'then i can removed the panel inside the horizontalview
horizontalview.panel.GetView(0).RemoveView
Next

if i remove only the panel inside horizontalview whit this: horizontalview.panel.GetView(0).RemoveView
the children remain initialized, This code dont worked fine.

I hope understand my english


horizontalpanel = ScrollView1.Panel.GetView(0)
For ic = horizontalpanel.Panel.NumberOfViews -1 To 0 Step -1
'Dont removeed the child
horizontalpanel.panel.GetView(0).RemoveView
Next
 

klaus

Expert
Licensed User
Longtime User
There is no need to post two times the same post.
How do you add the different views and where.
It would be much easier to help you if you posted your project as a zip file.

Try this code:
B4X:
For i = ScrollView1.Panel.NumberOfViews -1 To 0 Step -1
  ScrollView1.Panel.RemoveViewAt(i)
Next
Best regards.
 
Last edited:

mrussell014

Member
Licensed User
Longtime User
Cant find answers to database issue

:BangHead: I have read almost all the scrollview information. I have searched this site but found nothing for my delema. Doesn't mean it is not there, I just dont recognize it.

I used scrollview and other app's code to create an app that currently does what I want it to do. The final fronteer is to have the database after the the app closes. This is neccessary because the table is updated usually during each run, plus my initial file is 250,000 records.

My problem is I cant find the files so I can copy them to a safe place. I can find my csv file that is safe in the assets folder but that is all. I expect to run this app on all androids so I need a generic code to save my updates for further use.

Thank you for reading, Any help is apreciated.

Thanks,
Mike
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…