HorizontalScrollView

AHilberink

Active Member
Licensed User
Longtime User
Hi,

Can someone tell me how to use HorizontalScrollView?

I read a lot of posts, but I cann't get it work.

I want to scroll through 3 panels and start on the first.

How to add more panels? I am getting all panells on one screen.

Part of the source:
==
ImageFront.Bitmap = LoadBitmap(ImageBigPath, sel.Four & "f.jpg")
HorizontalScrollView1.Panel.AddView(ImageFront,0,0,100%x,100%y)

ImageFront.RemoveView
ImageFront.Bitmap = LoadBitmap(ImageBigPath, sel.Four & "b.jpg")
HorizontalScrollView1.Panel.AddView(ImageFront,0,0,100%x,100%y)

Beschrijving1.Text = sel.Seven
Beschrijving1.Enabled = False
HorizontalScrollView1.Panel.AddView(Beschrijving1,0,0,100%x,100%y)

HorizontalScrollView1.Visible = True
==

I think it would be something basicly, but I am a Newbie, sorry.

Thanks,
André
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
HorizontalScrollView behaves exactly like ScrollView. These examples are relevant: ScrollView examples summary

There are two issues with your code:
1. You are adding ImageFront and then removing it. Why?
2. You are adding the views to the same position.
Instead try:
B4X:
HorizontalScrollView1.Panel.AddView(ImageFront,0,0 ,100%x,100%y)
...
HorizontalScrollView1.Panel.AddView(Beschrijving1, 100%x,100%y,100%x,100%y)
 
Upvote 0

AHilberink

Active Member
Licensed User
Longtime User
Hi Erel,

Thanks. Now I understood more of its working.

I still got a problem. Scrolling to the second part, it only shows half and the third isn't available at all.

Part of source:
==
Alfabet.Visible = False

ImageFront.Bitmap = LoadBitmap(ImageBigPath, sel.Four & "f.jpg")
ImageFront.Gravity = Gravity.Fill
HorizontalScrollView1.Panel.AddView(ImageFront,0,0,100%x,100%y)

ImageBack.Bitmap = LoadBitmap(ImageBigPath, sel.Four & "b.jpg")
ImageBack.Gravity = Gravity.Fill
HorizontalScrollView1.Panel.AddView(ImageBack,100%x,0,100%x,100%y)

Beschrijving1.Text = sel.Seven
Beschrijving1.Enabled = False
HorizontalScrollView1.Panel.AddView(Beschrijving1,200%x,0,100%x,100%y)

HorizontalScrollView1.Visible = True
==

Can you tell me what I still do wrong?

Thanks,
André
 
Upvote 0

AHilberink

Active Member
Licensed User
Longtime User
Hi Klaus,

Now its shows everything.

Is it possible to Slide per panel? Now I can stop in the middle of the second or third one.

What I was trying to do, is a sliding per image, just slide a bit and auto park on the full second one and so on.

I hope I descripe it correctly, so you know what I meant to do.

Thanks,
André
 
Upvote 0

AHilberink

Active Member
Licensed User
Longtime User
Hi Klaus,

Thanks. This was what I was looking for.

I found a nice example/source of Corwin.

Thanks,
André
 
Upvote 0

cooperlegend

Active Member
Licensed User
Longtime User
Horizontal Scroll Panel

Im struggling with this panel, two issues.

I firstly want to dynamically set the inner scroll width and secondly what to programatically add buttons with events to this panel.

So that I can have a scrolling horizontal panel of width 200 * iCount
and iCount buttons with events.

So that I can simply feed in a value of say 20 into iCount and I get 20 buttons (btn1 to btn20) with events btn1_Click to btn20_Click

Ideas?

Thanks
 
Upvote 0

cooperlegend

Active Member
Licensed User
Longtime User
Thanks Erel,

So what is the width parameter in .initialize used for (I tried this and my view disappeared)?

I had no problem creating these buttons as btn1 to btn20, but the _Click events created didn't work.... Can I email you some code later to show what I had to do to work around this. I sure it can be made simpler. (I don't want to post my code to a forum as it is sensitive code).
 
Upvote 0

cooperlegend

Active Member
Licensed User
Longtime User
I see, so if you use initialise then this creates a new scrollview (rather than using the designer), makes sense, I will try that, thanks.

OK below is a sample of my code, if possible can you explain how I can refine this so that it can all be generated by a simple loop of iCount times.

B4X:
Sub Globals
   Dim lblShow1 As Label
   Dim lblShow2 As Label
   Dim lblShow3 As Label
        '..... etc. 50+ time...
   
        Dim Scroll As HorizontalScrollView
End Sub



Sub lblDo1_Click
   lblShow1.Text = DisplayValue(1) ' Does stuff with value 1
End Sub

Sub lblDo2_Click
   lblShow2.Text = DisplayValue(2) ' Does stuff with value 2
End Sub

Sub lblDo3_Click
   lblShow3.Text = DisplayValue(3) ' Does stuff with value 3
End Sub
' etc 50+ times....


Sub Build ScrollView
   Dim iCount As Int

   Dim xPos As Int
   Dim yPos As Int
   Dim radius As ColorDrawable
        Dim sld As StateListDrawable
   Dim viewPanel As Panel
   
   xPos = 0
   yPos = 0

   viewPanel = ScrollScores.Panel
   For iCount = ScrollScores.Panel.NumberOfViews - 1 To 0 Step -1
      viewPanel.RemoveViewAt(iCount)
   Next

   For iCount = 50 ' or more
         Dim lblS As Label
         lblS.Initialize("")
         lblS.Text = DisplayValue(iCount)
         viewPanel.AddView(lblS, (iCount * 220-140) , (iCount * 90 + 20) , 50 , 80)
         
         Select iNum
            Case 1
               lblShow1 = lblS
            Case 2
               lblShow2 = lblS
            Case 3
               lblShow3 = lblS
                                ' Etc 50+ times.....
         End Select
         
         Dim lblDo As Label
         lblDo.Initialize("lblDo" & iCount)
         lblDo.Text = "Click To Show Value"
         viewPanel.AddView(lblDo, (iCount * 220-90) , (iCount * 90 + 20) , 80 , 80 )
      Next
   Next

End Sub

As you can see, quite long winded when I have over 50+ labels/buttons and I use both the _Click and _LongClick events for each label.

I would like to refine this so that I can loop to define all the label/buttons and create all the events and get this down to a much smaller size :)
 
Upvote 0
Top