Android Question Horizontal ScrollView with image

Matteo Granatiero

Active Member
Licensed User
I downloaded this project from this site but I can not replace the colors with images contained in a route of the phone
 

Attachments

  • HScrollPages.zip
    409.3 KB · Views: 326

npsonic

Active Member
Licensed User
Here's example with images

B4X:
Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Main")
    hsvPages.Panel.Width = 4 * hsvPages.Width
    
    hsvTimer.Initialize("hsvTimer", 200)
    
    objPages.Target = hsvPages
    objPages.SetOnTouchListener("hsvPages_Touch")
    
    Dim bd As BitmapDrawable
    bd.Initialize(LoadBitmap(File.DirAssets,"icon.png"))
    
    Dim i As Int
    For i = 0 To 3   
        pnlPages(i).Initialize("")
        pnlPages(i).Background = bd
        hsvPages.Panel.AddView(pnlPages(i), i * hsvPages.Width, 0, 100%x, 100%y)
    Next
End Sub
 
Upvote 0

Matteo Granatiero

Active Member
Licensed User
Here's example with images

B4X:
Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Main")
    hsvPages.Panel.Width = 4 * hsvPages.Width
   
    hsvTimer.Initialize("hsvTimer", 200)
   
    objPages.Target = hsvPages
    objPages.SetOnTouchListener("hsvPages_Touch")
   
    Dim bd As BitmapDrawable
    bd.Initialize(LoadBitmap(File.DirAssets,"icon.png"))
   
    Dim i As Int
    For i = 0 To 3  
        pnlPages(i).Initialize("")
        pnlPages(i).Background = bd
        hsvPages.Panel.AddView(pnlPages(i), i * hsvPages.Width, 0, 100%x, 100%y)
    Next
End Sub
what is objpages?
 
Upvote 0

Matteo Granatiero

Active Member
Licensed User
It's from your example. Seems to be Reflector
it works but it loads 8 times only 1 image, in the path there are 8 images
B4X:
  Activity.LoadLayout("Main")
    hsvPages.Panel.Width = 4 * hsvPages.Width
   
    hsvTimer.Initialize("hsvTimer", 200)
   
    objPages.Target = hsvPages
    objPages.SetOnTouchListener("hsvPages_Touch")
    root=File.DirRootExternal
    path1 = root & "/BetaVersion/"
    For Each f As String In File.ListFiles(path1)
    Dim bd As BitmapDrawable
    bd.Initialize(LoadBitmap(path1,f))
   
    Dim i As Int
    For i = 0 To 8
        pnlPages(i).Initialize("")
        pnlPages(i).Background = bd
        hsvPages.Panel.AddView(pnlPages(i), i * hsvPages.Width, 0, 100%x, 100%y)
    Next
    Next
 
Upvote 0

npsonic

Active Member
Licensed User
it works but it loads 8 times only 1 image, in the path there are 8 images
B4X:
  Activity.LoadLayout("Main")
    hsvPages.Panel.Width = 4 * hsvPages.Width
 
    hsvTimer.Initialize("hsvTimer", 200)
 
    objPages.Target = hsvPages
    objPages.SetOnTouchListener("hsvPages_Touch")
    root=File.DirRootExternal
    path1 = root & "/BetaVersion/"
    For Each f As String In File.ListFiles(path1)
    Dim bd As BitmapDrawable
    bd.Initialize(LoadBitmap(path1,f))
 
    Dim i As Int
    For i = 0 To 8
        pnlPages(i).Initialize("")
        pnlPages(i).Background = bd
        hsvPages.Panel.AddView(pnlPages(i), i * hsvPages.Width, 0, 100%x, 100%y)
    Next
    Next
Of course you have to create new bitmap for every background like this

B4X:
Dim path1 As String = File.Combine(File.DirRootExternal,"/BetaVersion/")
Dim files As List = File.ListFiles(path1)
Dim bd As BitmapDrawable
  
For i = 0 To files.Size - 1
    Dim p As Panel : p.Initialize("")
    hsvPages.Panel.AddView(p, i * hsvPages.Width, 0, 100%x, 100%y)
    bd.Initialize(LoadBitmapSample(path1,files.Get(i),p.Width,p.Height))
    p.Background = bd
Next

also I'm not sure for which purpose this app is going to be, but target api 14 and what you are doing with this example pretty much denies you ever sharing this kind of app in PlayStore.
 
Upvote 0

Matteo Granatiero

Active Member
Licensed User
Of course you have to create new bitmap for every background like this

B4X:
Dim path1 As String = File.Combine(File.DirRootExternal,"/BetaVersion/")
Dim files As List = File.ListFiles(path1)
Dim bd As BitmapDrawable
 
For i = 0 To files.Size - 1
    Dim p As Panel : p.Initialize("")
    hsvPages.Panel.AddView(p, i * hsvPages.Width, 0, 100%x, 100%y)
    bd.Initialize(LoadBitmapSample(path1,files.Get(i),p.Width,p.Height))
    p.Background = bd
Next

also I'm not sure for which purpose this app is going to be, but target api 14 and what you are doing with this example pretty much denies you ever sharing this kind of app in PlayStore.
load only 4 images / 8 images.... why?
 
Upvote 0
Top