Android Question CustomScrollView does not scroll full page only half?

ronovar

Active Member
Licensed User
Longtime User
I have atatched simple project demo...when i press on remote up it scrolls dull page when i press down button on remote controll it scrolls half page...how to fix this?

Here is what i get half scroll picture:

picture.png

How to fix to get full scrolling up and down?
 
Last edited:

mangojack

Well-Known Member
Licensed User
Longtime User
In your last thread HERE .. you stated the problem had been fixed .. apparently @Erel had suggested placing a transparent button in each of the CLV item panels with the same height. I cannot find any reference to this trick ... and without any additional code I cant see how this would work.

I don't see how the remote Up works as I can only see Logging of the CLV scrollview ScrollPosition but nowhere can I see any code to manually set it.

B4X:
Sub Activity_KeyUp (KeyCode As Int) As Boolean
   Log(GetMasterPosition(clvMasterCh.ScrollPosition))
End Sub

Sub GetMasterPosition(ScrollPosition As Int) As Int
   Log(ScrollPosition)
   Return Round(ScrollPosition/252)
End Sub

your idea is on the right track. You have to get the LAST ScrollView.ScrollPosition .. then do calculation using your set panel heights
and then set the new scroll position.
B4X:
Public Sub ScrollToPosition(ScrollPosition As Int)
   sv.ScrollToNow(ScrollPosition)
End Sub

The trick is getting the FINAL ScrollView.ScrollPosition. @Erel has suggested using a timer in the ScrollChanged event to do this ..

See these threads... In one @klaus has an example which demonstrates this .. Unfortunately this is a horizontal scroll, but you might be able to adapt it.

ScrollView Magnetic Position ...

HSV Need End of ScrollEvent ...

extra .. I forgot to mention the CLV has JumpTo function also ..
B4X:
'Scrolls the list to the specified item.
Public Sub JumpToItem(Index As Int)

Cheers
 
Last edited:
Upvote 0

ronovar

Active Member
Licensed User
Longtime User
Your app crashed on this line:
JSON.Initialize(File.ReadString(File.DirDefaultExternal, "channels.json"))

File not found.

Just Change File.DirDefaultExternal to File.DirAssets...

When i use JumpToItem(5) in Sub Activity_KeyUp (KeyCode As Int) As Boolean i get exit from apk without error...so i can't use JumpToItem...i don't know why is exiting from apk.
 
Upvote 0

mangojack

Well-Known Member
Licensed User
Longtime User
remove this from Activity_Create ..(this is why app was crashing)
B4X:
  'CALL - 0st Item
   Activity_KeyUp ("20")

Activity_KeyUp(KeyCode as Int) is expecting an INT anyway .. Not A String


for testing i have placed a button on the main panel .. All works fine.
B4X:
Sub Button1_Click  
  
   Log(GetMasterPosition(clvMasterCh.ScrollPosition))  
  
   clvMasterCh.JumpToItem(20)
  
End Sub
 
Upvote 0

ronovar

Active Member
Licensed User
Longtime User
just comment two DoEvents and one sv.ScrollPosition = top an using JumpToItem(20) -- 20 is from counter, and now apk scrolls up and down right but down scrolling is slower that up scrolling...how to fix this? When i press up it scrolls immediately up without delay and when i press down it scrolls down with delay...first is half scrolled and then is full scrolled down...so delay is about cca 1sec...how to speed up down scrolling?

For exiting apk when using JumpToItem was problem double doevents. Now need idea how to fix faster scrolling to Down with JumpToItem...i think it needs some optimization this function...

B4X:
'Scrolls the list to the specified item.
Public Sub JumpToItem(Index As Int)
    Dim top As Int
    Dim p As Panel
    For i = 0 To Min(Index - 1, items.Size - 1)
        p = panels.Get(i)
        top = top + p.Height + dividerHeight
    Next
    sv.ScrollPosition = top
    'The scroll position doesn't always gets updated without two calls to DoEvents
    'DoEvents
    'sv.ScrollPosition = top
    'DoEvents
End Sub
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Have you tried it this way?

B4X:
Public Sub JumpToItem(Index As Int)
    Dim top As Int
    Dim p As Panel
    For i = 0 To Min(Index - 1, items.Size - 1)
        p = panels.Get(i)
        top = top + p.Height + dividerHeight
    Next
        CallSubDelayed2(Me,"JumpTo",top)
    'The scroll position doesn't always gets updated without two calls to DoEvents
    'DoEvents
    'sv.ScrollPosition = top
    'DoEvents
End Sub
public Sub JumpTo(item As Int)
    sv.ScrollPosition = item
End Sub
 
Upvote 0

ronovar

Active Member
Licensed User
Longtime User
remove this from Activity_Create ..(this is why app was crashing)
B4X:
  'CALL - 0st Item
   Activity_KeyUp ("20")

Activity_KeyUp(KeyCode as Int) is expecting an INT anyway .. Not A String


for testing i have placed a button on the main panel .. All works fine.
B4X:
Sub Button1_Click 
 
   Log(GetMasterPosition(clvMasterCh.ScrollPosition)) 
 
   clvMasterCh.JumpToItem(20)
 
End Sub

Try to put 100items or more then scrolling will not work any more full scroll only half..i tryed now and i think there is bug in scrollview component or code...because if i put:

B4X:
'ADD - Master Items
    For Ch = 1 To 50
        clvMasterCh.Add(CreateChannelListMaster(Ch, clvMasterCh.AsView.Width, 169dip, "hayatbih.png", "Channel "&Ch, "Inspektori za životinje", "12:45", "13:10", "Na prvoj liniji: Epizoda 3 Prikazuje se život leoparda u divljini kako lovi i preživljava..."), 167dip, Channels)
    Next

Scrolling works perfect...if i put this:

B4X:
'ADD - Master Items
    For Ch = 1 To 100
        clvMasterCh.Add(CreateChannelListMaster(Ch, clvMasterCh.AsView.Width, 169dip, "hayatbih.png", "Channel "&Ch, "Inspektori za životinje", "12:45", "13:10", "Na prvoj liniji: Epizoda 3 Prikazuje se život leoparda u divljini kako lovi i preživljava..."), 167dip, Channels)
    Next

Scroling works only half scrolling..so why is this so?
 
Upvote 0

mangojack

Well-Known Member
Licensed User
Longtime User
Try to put 100items or more then scrolling will not work any more full scroll only half..i tryed now and i think there is bug in scrollview component or code...

Can you repost your project .. IDe Menu > File > Export as Zip
 
Upvote 0

ronovar

Active Member
Licensed User
Longtime User
Here is it...example..just try to change line 48 (For Ch = 1 To 150) to: 50...1000 and you will see tht for first 50items it works excellent more that 50 it does not scroll correctly.
 

Attachments

  • NonWorkingCustomListView.zip
    16.4 KB · Views: 148
Upvote 0

mangojack

Well-Known Member
Licensed User
Longtime User
I tested with 1000 items on my tablet .. to me it all looks ok , slow or fast . although a little hard to tell exactly with the SV being a little small.
What devices are you testing this on ?
Do you need 1000 items loaded or was this just for test purposes.

I thought your main problem was getting the individual panels to stop at scroll end so the whole panel is in view?
 
Upvote 0

ronovar

Active Member
Licensed User
Longtime User
I ime getting half scrool like in picture in first post (greeb background half scrolled panel down)...so i don't get idea why is on my android device over 50items scrolling half? I see in Log

B4X:
Sub GetMasterPosition(ScrollPosition As Int) As Int
    Log(ScrollPosition)
    Return Round(ScrollPosition/250)
End Sub

That first 50items have height in scoroller 250 witch is correct if i put 60 items or more it height is 125 and why is this half?
 
Upvote 0

mangojack

Well-Known Member
Licensed User
Longtime User
That first 50items have height in scoroller 250 witch is correct if i put 60 items or more it height is 125 and why is this half?

I think you are getting confused ..

your code above is simply logging the current SV Scroll position divided by 250 ?? This has nothing to do with your panel size.

You are adding a CLV (ScrollView) to the Activity (167dips height)
Then you are adding 100 Line items (pnlMaster) to this CLV (167dips height)
B4X:
'ADDVIEW - CustomListViews
   Activity.AddView(clvMasterCh.AsView, 97dip, 389dip, 407dip, 167dip)  '@@@ 167Dip size of the ScrollView Window

   'ADD - Master Items
   For Ch = 0 To 100
     clvMasterCh.Add(CreateChannelListMaster(Ch, clvMasterCh.AsView.Width, 169dip, "hayatbih.png", "Channel Test", "12:45", "13:10", "Testing 123"), 167dip, Channels)
   Next
               '@@@ 167dip is the size of pnlMaster (that contains your other views)
Each line item (pnlMaster) that is added to the CLV (100 of them) is the same size as the CLV (ScrollView) window
They do not get smaller as you add them .

I believe you are still referring to the fact the WHOLE of 1 single pnlMaster is not visible in the CLV viewing window when the scolling has STOPPED.
(Part of 2 Panels are visible)

Maybe i'm misunderstanding you .... If Not Please re-read post# 3
 
Last edited:
Upvote 0

mangojack

Well-Known Member
Licensed User
Longtime User
I ime getting half scrool like in picture in first post (greeb background half scrolled panel down)...so i don't get idea why is on my android device over 50items scrolling half?
That first 50items have height in scoroller 250 witch is correct if i put 60 items or more it height is 125 and why is this half?

I have altered you project to include something @klaus did HERE ... with a HorizontalScrollView .

Basically a Timer was introduced to calculated the approximate scroll time / duration so the Final SV Scroll position can be got and used to display a complete
panel in the SV viewing window. It has been altered to work ( ? ) on a vertical scrollview .

To be honest .. I am unsure of a few factors used in the calculation .. ( Help @klaus ) and it was manually tweaked to produce a reasonable result on your CLV Example .

It was more to supply an example of what is required to solve your problem. ( I still think this is your request ... If not , forget .. and I'm outa here ;))

Cheers
 

Attachments

  • CLVTimerScroll.zip
    17.2 KB · Views: 143
Upvote 0

ronovar

Active Member
Licensed User
Longtime User
thanks i will try this today and post result...currently i im adding timer and epg to apk so i will today try your solution and replay back...Thanks for helping me out to solve this problem..i was thinking that android os will automatically care about scroll positions...if is possible to disable scrolling with java object (reflector?) and then scroll using jumptoposition because i see that first scroll os to half and then is called jumptoposition witch scrolls correctly but it is slow..i will try to use your example and will report back.
 
Upvote 0

mangojack

Well-Known Member
Licensed User
Longtime User
You might want to try this also .. it uses a simplified method ( polls the timer every nMillisecs) to detect if scrolling has finished and properly displaying the panels ..
It seemed to me a much better and consistent result ... although it failed on occasional 'multiple scrolls'

If your interested .. then it could be refined / worked on for a better result .. ie ask an expert ;)
 

Attachments

  • CLVTimerScroll 2.zip
    17.4 KB · Views: 143
Upvote 0

ronovar

Active Member
Licensed User
Longtime User
Thanks for posting modified project and helping me out..but it does not work smooth as it should be...does exist any other way of doing it to scrool smooth? When i scroll up it scrolls so nice and fast....but scrolling down it is slow and half ways scrolling...does using reflector can i set somewhere with android api height of panel to be scrolling correctly?

Interesting is when scrollview have 50 items it scrolls smooth up and down, nice and fast like it should be...when adding more that 50 items it scrolls up correct, but down scorlling is half way..i think that scrollview have limitation in android os to 50 items ( or limit 50items x 250dip = 12500dip)...so the idea is how to set with reflector using calling android api to set it to accept larger that 50 items
 
Upvote 0

mangojack

Well-Known Member
Licensed User
Longtime User
What Devices are you testing on ?? Are you Scrolling Manually (with fingers) or some form of Remote ?

The last example posted scrolled the same both up and down (tested 150 items)
Although the method used to display a Full Panel in viewing area after Scroll has Finished was " Crude " ... it shows what has to be done to make this work.

i think that scrollview have limitation in android os to 50 items ( or limit 50items x 250dip = 12500dip)

I cannot find any thread stating maximum ScrollView Items.... But based on @Erel 's statement ...
CustomListView is an implementation of a list based on ScrollView
CustomListView is suited for lists of up to 1000 or 2000 items.


Why do you make reference again to panel size of 250dip ?? when your scrollview height AND all item panels are 167dip ... Please re-read post# 13

If time permits I will make a simplified demo to demonstrate
 
Upvote 0

ronovar

Active Member
Licensed User
Longtime User
Ok can you make example of 150items or more in scrollview and post here demo code? I im currently programming epg for apk...but have limit to 50 items in channels list and working perfectly...but i need for 150 to 500 items scroller...i im using remote control...not smartphone android so touch is not good for me because i use remote controll to go up or down throught channels with remote key up and down..using 50 items it works excellent without error or delay..but adding more items that 50 it scrolls down half way and up scrolls perfectly...i don't have knowledge of scrollview limitations and functonality but i think that problem is somwhere in scrollview code..when you have time it will be excellent to post code that works with more that 50 items.

Thanks.
 
Upvote 0

mangojack

Well-Known Member
Licensed User
Longtime User
Ok can you make example of 150items or more in scrollview and post here demo code? I im currently programming epg for apk...but have limit to 50 items in channels list and working perfectly...but i need for 150 to 500 items scroller...i im using remote control...not smartphone android so touch is not good for me .........

Thanks.


I have just tested with 1000 items .. All OK It does take a while to load though .
I will still try for a simpler demo just using ScrollView .
 

Attachments

  • CLVTimerScroll 3.zip
    17.4 KB · Views: 125
Upvote 0
Top