Android Question Scroll View Understanding and Help

IslandMedic

Member
Licensed User
Longtime User
In the last week my learning curve for b4a has been huge and I am doing pretty dam good for where I am starting from. However I really suck at screen design and understanding how the design elements all work together. Here is what i am trying to do.

Imagine if you will. A screen with two labels stacked on top of one and another. They each take about 1/3 of the screen, with the last third being some control buttons.(full width btw). I was going to edit the text of each label as information came in. Then I realized I couldn't scroll back to read what was said before. Then I looked and there was something call a scroll view, Whoot whoot that would solve my issue.

I have downloaded the example long text.zip and tried playing with it. The only thing I understand is that the label where the text goes has to be higher than the scrollview box, that is what causes the scrolling effect.

After that I am really struggling. I am wondering if someone could help me design this view. So some questions if i may?

1. is there a limit to how much lines of text can be scrolled through and how is that determined? label box size or scroll view size? or is this a matter of FIFO kind of thinking?

2. Can I have two scroll views be on the same screen at the same time. Think of two channels of info in real time coming into the same screen and being able to scroll through them.

3. does each label need to be in a separate layout? Assuming that both scroll views are on the same layout page.

4. How does each label get associated or attached to a specific scroll view?

As you can see I am really struggling with this design process. I found a rather good video to help but the guy is in Spanish. <sigh>.

A bit long but thanks for helping if you can.

Brad
 

eurojam

Well-Known Member
Licensed User
Longtime User
Hi Brad,
some answers, but not all...;)

1: A scrollview is a view which has a inner and a outer height: if inner > outer then you will see the scrollbar
B4X:
Dim sv As ScrollView
sv.Initialize(1000dip) 'this defines the inner height
Activity.Addview(sv,0,100%x, 0, 200dip) ' now it will be scrollable, because only 20% of the inner panel will be visible
You can add whatever you want to your scrollbar, images text other panels. and you can also load layouts to the panels you loaded before
B4X:
    Dim p As Panel
    p.Initialize("p1")
    sv.panel.AddView(p,0,0,100,100)
    p.LoadLayout("panelLayout1")
you can control the innerheight at any point. If your content of the scrollview grows you can adapt the inner height:
B4X:
sv.Panel.Height=2000dip

so far for this morning from my side, hope this helps a bit

stefan
 
Last edited:
Upvote 0

klaus

Expert
Licensed User
Longtime User
A ScrollView is an object like other Views.
It has an internal Panel which can be higher than the ScrollView itself.
There can be more than one ScrollView on the screen at the same time.

Did you have a look at the ScrollView examples summary thread.

1) I don't know of any limit, but if the text becomes very long the scrolling will become unefficient and 'boring'.
You should have a closer look at the LongTextSimple example, the height of the text is calculated with the MeasureMultilineTextHeight function from the StringUtils library and set it to the Label and ScrollView.Panel Height property.

2) Yes.

3, 4) This depends on how ou define the layouts.
You need one layout with the two ScrollViews and the buttons.
Then you can have one layout file for the Label and load this same layout on each ScrollViews with
B4X:
ScrollView1.Panel.LoadLayout("LayoutLabel")
ScrollView2.Panel.LoadLayout("LayoutLabel")

Or you can add one Label to each ScrollView internal panel with in the code:
B4X:
Dim Label2 As Label
Label2.Initialize("")
ScrollView1.Panel.AddView(Label1, ...

Dim Label1 As Label
Label1.Initialize("")
ScrollView1.Panel.AddView(Label1, ...
 
Upvote 0

IslandMedic

Member
Licensed User
Longtime User
Thank you for the replies. I have been going through the examples and I am learning alot. Where I am stumbling is the glue that holds all the elements together. I am still wrapping my head around the environment. So when I try to use something like scroll view I get how it works but don't understand the structure underneath so I wonder around in the dark for a while through trial and error till I get it (sort of). So thank you for the help and I appreciate it. It must get a little frustrating at times with questions like mine. Just know that it is the community plays a large roll in making a product successful.
 
Upvote 0
Top