Android Question Need help sizeing HSV

tsteward

Well-Known Member
Licensed User
Longtime User
I have attached a sample app. In my real app the number of edittexts vary subject to a database.

I would like the scroll to only scroll back and forth enough to see the relevant edittexts but it seems to scroll much further. Hoping to code this to work on multiple screen sizes. And where the screen is wide enough to centre the display.

Any help appreciated :)
 

Attachments

I'm not sure what you want to do, but:
The "thing" that scrolls is the HorizontalScrollView1.Panel , so you need to adjust its size :
HorizontalScrollView1.Panel.Width = left
and then the rest accordingly.
HorizontalScrollView1.Width should not change and probably be 100%x
The panel to which you add the ET's should be the scrollview panel !
 
Upvote 0
Are you sying the ETs should be on HorizontalScrollView1 and not on panel1?

Please correct me but i thought:
You set the HSV to the width of the screen. Then if I put a panel containing whatever and if that panel was wider thea the HSV you could drag that panel back and forth.
I'm not sure what you want to do
I want to add ETs where the qty of them changes each time the activity is loaded. I want to be able to scroll to see all th ETs but not scroll too far.
When used on a larger screen and scrolling is not required I want the display to be centred.
 
Upvote 0
Like I said, put the scrollview to screen size, delete panel1.
Put the ETs on the scrollview panel and adjust its size to the total size of the ETs.
You should have scrolling exactly as you want.
Putting the scroll to the center should be done with .ScrollPosition
 
Upvote 0
Alright I'm obviously dumb, sorry to be so frustrating but how do I add the ET's to HorizontalScrollView1 as there is no Add feature?
 
Upvote 0
Alright I'm obviously dumb, sorry to be so frustrating but how do I add the ET's to HorizontalScrollView1 as there is no Add feature?

HorizontalcrollView.panel.AddView(...)

But seems to me that this panel is movable to the left over the left edge of the scrollview and vice versa on the right, which tsteward would like to avoid.

I tried this:
Code: Copy
Sub HorizontalScrollView1_ScrollChanged(Position As Int)
    Log("Position = " & Position)
    If Position < 0 Then
        HorizontalScrollView1.left = 0
        Return
    End If
   
    If Position > mHSVMaxPos Then
        HorizontalScrollView1.left = mHSVMaxPos
        Return
    End If
   
End Sub

but it can not work, you should be able to "stop the event itself"
 
Last edited:
Upvote 0
I changed the code to this but I can't set scroll width?
Code: Copy
Sub Globals
    Dim HorizontalScrollView1 As HorizontalScrollView
    Dim PanelMain As Panel
    Dim ET(11) As EditText
    Dim left As Int
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Layout1")
    left = 2dip
    For i = 0 To 10
        ET(i).Initialize("")
        HorizontalScrollView1.Panel.AddView(ET(i), left, 2, 45dip, 45dip)
        left = left + 47dip
    Next
    HorizontalScrollView1.Width = left
End Sub
 
Upvote 0
I think this is what you are looking for.
Code: Copy
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("Layout1")
    HorizontalScrollView1.Panel.LoadLayout("panelview")
    Panel1.Height = HorizontalScrollView1.Height
    HorizontalScrollView1.Panel.Color = Colors.Blue
    Panel1.Color = Colors.Blue
    left = 2dip
    For i = 0 To 10
'    For i = 0 To 3
        ET(i).Initialize("")
        ET(i).Text = i
        Panel1.AddView(ET(i), left, 2, 45dip, 45dip)
        left = left + 45dip
    Next
    Panel1.Width = left
    Panel1.Top = 0
    If left > HorizontalScrollView1.Width Then
        Panel1.left = 0
        HorizontalScrollView1.Panel.Width = left
    Else ' if screen is wide enough to dispay all then centre display
        Panel1.left = (HorizontalScrollView1.Width/2)-(Panel1.Width/2)
        HorizontalScrollView1.Panel.Width = 100%x
    End If
End Sub
I added also text in the EditText views and colors for the panels to see what happens.
 

Attachments

  • picture1.jpg
    picture1.jpg
    21.2 KB · Views: 286
  • picture2.jpg
    picture2.jpg
    16.8 KB · Views: 269
Upvote 0
Back
Top