Android Question scrollview sample (or alternate idea)

Zeev Goldstein

Well-Known Member
Licensed User
Longtime User
hi

i need to create a view that will allow longer view that actual screen (too many items)
searching the forum brought up scrollview
i tried to find a sample as i couldn't find my way with it
is there a simple sample for a scrollview with a few buttons on it so i can use it for my needs?
thanks
 
Solution
what you are doing is wrong
you create a panel with height 100%y and add it to the activity then you create the sv inner panel height also to 100%. so how should the height be larger then 100%y if you set both to 100%y???

this is how you should do it

B4X: Copy
Sub Globals
    Dim sv As ScrollView
End Sub

Sub Activity_Create(FirstTime As Boolean)
    sv.Initialize(1000dip) 'height of the panel in Layout
    Activity.AddView(sv,0,0,100%x,100%y)
    sv.Panel.LoadLayout("Layout")
End Sub

example included
You already got told to use xcustomListview.
Why ignoring all the suggestions?

Use xCustomListview

is there a simple sample for a scrollview with a few buttons on it so i can use it for my needs?
Start with the Example provided

 
Upvote 0
You already got told to use xcustomListview.
Why ignoring all the suggestions?

Use xCustomListview


Start with the Example provided

who told me?
when?
your respond is the only one to my post
 
Upvote 0
You can define the scrollview (SCV) by the designer, in my case I made it on top third of the screen, then set the internal panel size and added by code a imageview (Iv1) . You can add more views to the internal panel.
B4X: Copy
    IV1.Initialize("")
    SCV.Panel.Width = 100%x
    SCV.Panel.Height = 100%y
    SCV.Panel.AddView(IV1, 0, 0, 100%x,  100%y)

If needed, use the event:
B4X: Copy
Private Sub SCV_ScrollChanged(Position As Int)
    Log(Position)
End Sub
 
Last edited:
Upvote 0
You can define the scrollview (SCV) by the designer, in my case I made it on top third of the screen, then set the internal panel size and added by code a imageview (Iv1) . You can add more views to the internal panel.
B4X: Copy
    IV1.Initialize("")
    SCV.Panel.Width = 100%x
    SCV.Panel.Height = 100%y
    SCV.Panel.AddView(IV1, 0, 0, 100%x,  100%y)
thanks

my plan is not to add a table or list like the ample i was referred to above

what want to do is have a layout that is longer that actual screen height so i can add textedits and buttons
if possible to take existing layout and add to it the ability to scroll as i need to add more elements

this i can't find

so from your sample code i see you load LV1 - can load to it my panel or layout and by that have the scroll ability?
my app is B4A
 
Upvote 0
Yes !, and you can define all your added views in the designer as a layout file and set the internal panel with it.
 
Upvote 0
Yes !, and you can define all your added views in the designer as a layout file and set the internal panel with it.
i'm sure i missed something
or just got it wrong

here's my code - i get errors on the SCV part
without it it loads but of course not as needed

can you help?

thanks
 
Upvote 0
Where? ?



Yes.. If you post some code ?
oops...

Code: Copy
Sub Activity_Create(FirstTime As Boolean)

    'Activity.LoadLayout("Layout")

    Pnl.Initialize("")
    Pnl.LoadLayout("Layout")
    Activity.AddView(Pnl,0,0,100%x,100%y)

    
    ''IV1.Initialize("")
    SCV.Initialize(0)
    SCV.Panel.Width = 100%x
    SCV.Panel.Height = 100%y
    SCV.Panel.AddView(Pnl, 0, 0, 100%x,  100%y)
    
End Sub
 
Upvote 0
Please use Xcustomlistview. Its easier than you can imagine
i did look at it as suggested above but from the sample i couldn't get to what i wanted
i don't need a scrolling list as in the sample, i need a form with buttons and textedits
the best will be the ability to take my existing views and load them into that "magical" customlistview
please mind that my app is classic b4a and quite old one
 
Upvote 0
what you are doing is wrong
you create a panel with height 100%y and add it to the activity then you create the sv inner panel height also to 100%. so how should the height be larger then 100%y if you set both to 100%y???

this is how you should do it

B4X: Copy
Sub Globals
    Dim sv As ScrollView
End Sub

Sub Activity_Create(FirstTime As Boolean)
    sv.Initialize(1000dip) 'height of the panel in Layout
    Activity.AddView(sv,0,0,100%x,100%y)
    sv.Panel.LoadLayout("Layout")
End Sub

example included
 

Attachments

Upvote 0
Solution
what you are doing is wrong
you create a panel with height 100%y and add it to the activity then you create the sv inner panel height also to 100%. so how should the height be larger then 100%y if you set both to 100%y???

this is how you should do it

B4X: Copy
Sub Globals
    Dim sv As ScrollView
End Sub

Sub Activity_Create(FirstTime As Boolean)
    sv.Initialize(1000dip) 'height of the panel in Layout
    Activity.AddView(sv,0,0,100%x,100%y)
    sv.Panel.LoadLayout("Layout")
End Sub

example

what you are doing is wrong
you create a panel with height 100%y and add it to the activity then you create the sv inner panel height also to 100%. so how should the height be larger then 100%y if you set both to 100%y???

this is how you should do it

B4X: Copy
Sub Globals
    Dim sv As ScrollView
End Sub

Sub Activity_Create(FirstTime As Boolean)
    sv.Initialize(1000dip) 'height of the panel in Layout
    Activity.AddView(sv,0,0,100%x,100%y)
    sv.Panel.LoadLayout("Layout")
End Sub

example included
thanks firstly
i knew i'm missing something
going to drill it...
 
Upvote 0
what you are doing is wrong
you create a panel with height 100%y and add it to the activity then you create the sv inner panel height also to 100%. so how should the height be larger then 100%y if you set both to 100%y???

this is how you should do it

B4X: Copy
Sub Globals
    Dim sv As ScrollView
End Sub

Sub Activity_Create(FirstTime As Boolean)
    sv.Initialize(1000dip) 'height of the panel in Layout
    Activity.AddView(sv,0,0,100%x,100%y)
    sv.Panel.LoadLayout("Layout")
End Sub

example included
wow
exactly what i was looking for - thank you
 
Upvote 0
Back
Top