Android Question Frustration with ScrollView Background

JackKirk

Well-Known Member
Licensed User
Longtime User
This is a small but highly irritating problem (at least to me).

I have a ScrollView that contains a series of Buttons.

The ScrollView has a border applied via its Background property.

If I scroll the Buttons, the top or bottom ScrollView border is visually overridden by whatever Button is currently going out of sight.

I have had no success searching the forums and have spent considerable time trying to find a SIMPLE solution - ie one that does not involve superimposing extra Panels etc.

Is there a SIMPLE solution?

Why doesn't a ScrollView border automatically stay on top anyrate?

Thanks in advance for any insights...
 

KMatle

Expert
Licensed User
Longtime User
Upvote 0

JackKirk

Well-Known Member
Licensed User
Longtime User
Hi,

Attached please find simple example which illustrates problem.

Border added to scrollview - it would be illogical to add it to inner panel would it not?

Any help appreciated...
 

Attachments

  • xxx.zip
    6.8 KB · Views: 185
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
The solution is simple. Put the ScrollView in a panel with border:
B4X:
Sub Activity_Resume
   
   Private wrk_clrdrw1, wrk_clrdrw2 As ColorDrawable

   Activity.Color = Colors.LightGray

   UI_scrollview.Initialize("")
   Dim p As Panel
   p.Initialize("")
   Activity.AddView(p, 24%x, 24%y, 52%x, 52%y)
   Activity.AddView(UI_scrollview, 25%x, 25%y, 50%x, 50%y)
   UI_scrollview.Panel.Height = 100%y
   wrk_clrdrw1.Initialize2(Colors.White, 4dip, 3dip, Colors.Black)
   p.Background = wrk_clrdrw1

   UI_button.Initialize("")
   UI_scrollview.Panel.AddView(UI_button, 2%x, 5%y, 46%x, 90%y)
   wrk_clrdrw2.Initialize2(Colors.Yellow, 4dip, 3dip, Colors.Red)
   UI_button.Background = wrk_clrdrw2
   UI_button.Text = "XXX"
   UI_button.TextColor = Colors.Black

End Sub
 
Upvote 0

JackKirk

Well-Known Member
Licensed User
Longtime User
Erel,

I understand this solution but it is not very satisfactory.

In my initial post I emphasised SIMPLE solution.

The reason why is that this little problem is in code inside a class that handles a raft of buttons and does a lot of other things like automatically size all button fonts and button heights so they all fit and are all uniform, adds a shadow effect, adds a visual click effect etc.

In the class I expose the scrollview so I can, amongst other things, resize height after initializing, use
SetVisibleAnimated for animated fades etc.

If I adopt your suggestion I would have to add a separate Height property to the class so both the scrollview and the border panel can be resized together.

This seems to me to be a pretty dirty workaround for what is increasing looking like an oversight in the design and coding of scrollviews.

But if there is no other way then I guess that's the way I will have to go.
 
Upvote 0
Top