Android Question Set height of ScrollView

anallie0

Active Member
Licensed User
Longtime User
hi
I have a panel with a imagewiew and one scrollview that contains a imageview.
in the first imageview load images of the same size, while in scrollview load images of different heights.
I can not set the height of the scrollview to fit the various images.
It always keeps the same height by squeezing the image that load.


B4X:
#Region  Project Attributes 
    #ApplicationLabel: Tabelle per Officina
    #VersionCode: 1
    #VersionName: 1.0
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: landscape
    #CanInstallToExternalStorage: true
#End Region

#Region  Activity Attributes 
    #FullScreen: True
    #IncludeTitle: false
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
   
    Dim panellista, panelimage As Panel
    Dim elenco As ListView
    Dim imagetitolo, imagenumeri As ImageView
    Dim immagine As Bitmap
    Dim scrollimage As ScrollView





End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
   
    Activity.LoadLayout("TabelOfficin")
    panellista.SetLayout(0%x, 0%y, 100%x, 100%y)'pannello e lista delle tabelle
    elenco.SetLayout(0%x, 0%y, 100%x, 100%y)
   
    panelimage.SetLayout(0%x, 0%y, 100%x, 100%y)'pannello immagini
    imagetitolo.SetLayout(0%x, 0%y, 100%x, 100%y)
        scrollimage.Initialize(100)
        imagenumeri.Initialize("imagenumeri")   
        panelimage.AddView(scrollimage, 0%x, 0%y, 100%x, 100%y)
        scrollimage.Panel.AddView(imagenumeri, 0%x, 0%y ,100%x, 100%y)
        imagenumeri.Gravity = Gravity.Fill
   
    crealista

End Sub


Sub crealista
Dim ico1, ico2, ico3, ico4, ico6, ico7, ico8 As Bitmap
   
    ico1.Initialize(File.DirAssets, "ico1.png")
    ico2.Initialize(File.DirAssets, "ico2.png")
    ico3.Initialize(File.DirAssets, "ico3.png")
    ico4.Initialize(File.DirAssets, "ico4.png")
    ico6.Initialize(File.DirAssets, "ico6.png")
    ico7.Initialize(File.DirAssets, "ico7.png")
    ico8.Initialize(File.DirAssets, "ico8.png")


elenco.AddTwoLinesAndBitmap("            FILETTATURA", "            Metrica passo fine", ico1)
elenco.AddTwoLinesAndBitmap("            FILETTATURA ", "            Metrica passo grosso", ico1)
elenco.AddTwoLinesAndBitmap("            FILETTATURA  ", "            Gas cilindrica", ico1)
elenco.AddTwoLinesAndBitmap("            FILETTATURA   ", "            Gas conica", ico1)
elenco.AddTwoLinesAndBitmap("            FILETTATURA    ", "            Whitworth BSW", ico1)
elenco.AddTwoLinesAndBitmap("            FILETTATURA     ", "            NPT", ico1)
elenco.AddTwoLinesAndBitmap("            FILETTATURA      ", "            UNC_UNF_UNEF", ico1)
elenco.AddTwoLinesAndBitmap("            FILETTATURA       ", "            Trapezoidale", ico1)
elenco.AddTwoLinesAndBitmap("            CONO MANDRINO", "            DIN - Jacobs", ico2)
elenco.AddTwoLinesAndBitmap("            CONO MANDRINO ", "            Morse", ico2)
elenco.AddTwoLinesAndBitmap("            ABRASIVI", "            Flessibili", ico3)
elenco.AddTwoLinesAndBitmap("            ABRASIVI ", "            Rigidi", ico3)
elenco.AddTwoLinesAndBitmap("            VITI", "            Coppia serraggio", ico4)
elenco.AddTwoLinesAndBitmap("            Viti ", "            Tipo di intagli", ico4)
elenco.AddTwoLinesAndBitmap("            DUREZZA", "            Conversione", ico6)
elenco.AddTwoLinesAndBitmap("            LINGUETTE", "            ", ico7)
elenco.AddTwoLinesAndBitmap("            RIVESTIMENTO", "            Utensili", ico8)
elenco.AddTwoLinesAndBitmap("            RUGOSITA'", "            ", ico1)
elenco.AddTwoLinesAndBitmap("            TOLLERANZE", "            Geometriche", ico2)
elenco.AddTwoLinesAndBitmap("            TOLLERANZE ", "            Albero", ico2)
elenco.AddTwoLinesAndBitmap("            TOLLERANZE  ", "            Foro", ico2)


End Sub




Sub Activity_Click
panellista.Visible=True
   
End Sub


Sub Activity_KeyPress (KeyCode As Int) As Boolean

     
    If KeyCode = KeyCodes.KEYCODE_MENU Then  'intercettazione del tasto menu per non uscire dall'app.
        Return True
    End If
   
    If KeyCode = KeyCodes.KEYCODE_VOLUME_DOWN Then  'intercettazione del tasto volume- per non uscire dall'app.
        Return True
    End If
   
    If KeyCode = KeyCodes.KEYCODE_VOLUME_UP Then  'intercettazione del tasto volume+ per non uscire dall'app.
        Return True
    End If
   
    If KeyCode = KeyCodes.KEYCODE_BACK Then 'intercettazione del tasto back
                               
                If panelimage.Visible=True AND panellista.Visible=True Then
                panelimage.Visible=False
                scrollimage.ScrollPosition = 0
               
               
               
               
            Return True           
                End If
               
                If panellista.Visible=True Then
                panellista.Visible=False
               
            Return True           
                End If
   
           
   Else
            Activity.finish
    End If
   
    End Sub


Sub elenco_ItemClick (Position As Int, Value As Object)




Select Case Value

    Case "            FILETTATURA"
            immagine = LoadBitmap(File.DirAssets, "titolo metrica fine.png")
            imagetitolo.Height=immagine.Height*1.5
            imagetitolo.Bitmap = immagine
                scrollimage.SetLayout(0%x, imagetitolo.Height, 100%x, 100%y)
                imagenumeri.Bitmap = LoadBitmap(File.DirAssets, "metrica fine.png")
                scrollimage.Panel.Height=imagenumeri.Height*1.4
               
    Case "            FILETTATURA "
            immagine = LoadBitmap(File.DirAssets, "titolo metrica grossa.png")
            imagetitolo.Height=immagine.Height*1.5
            imagetitolo.Bitmap = LoadBitmap(File.DirAssets, "titolo metrica grossa.png")
                scrollimage.SetLayout(0%x, imagetitolo.Height, 100%x, 100%y)
                imagenumeri.Bitmap = LoadBitmap(File.DirAssets, "metrica grossa.png")
                scrollimage.Panel.Height=imagenumeri.Height*1.4


       
    Case "            FILETTATURA  "
            immagine = LoadBitmap(File.DirAssets, "titolo gas cilindrica.png")
            imagetitolo.Height=immagine.Height*1.5
            imagetitolo.Bitmap = LoadBitmap(File.DirAssets, "titolo gas cilindrica.png")
                scrollimage.SetLayout(0%x, imagetitolo.Height, 100%x, 100%y)
                imagenumeri.Bitmap = LoadBitmap(File.DirAssets, "gas cilindrica.png")
                scrollimage.Panel.Height=imagenumeri.Height*1.4
   
            Case "            FILETTATURA   "
            immagine = LoadBitmap(File.DirAssets, "titolo gas conica.png")
            imagetitolo.Height=immagine.Height*1.5
            imagetitolo.Bitmap = LoadBitmap(File.DirAssets, "titolo gas conica.png")
                scrollimage.SetLayout(0%x, imagetitolo.Height, 100%x, 100%y)
                imagenumeri.Bitmap = LoadBitmap(File.DirAssets, "gas conica.png")
                scrollimage.Panel.Height=imagenumeri.Height*1.4





End Select

panelimage.Visible=True
   
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub





Sub lista_Click
   
End Sub
Sub lista_LongClick
   
End Sub
Sub panelimage_Click
   
End Sub
Sub panelimage_LongClick
   
End Sub
 
Last edited:

eps

Expert
Licensed User
Longtime User
Your code is a little hard to follow, as it seems a bit wrongly laid out to me, however..

I guess you've looked at this post? http://www.b4x.com/android/forum/threads/scrollview-example.6612/

The code there indicates a loop, which then sets the top of the ScrollView Panel as it goes. You don't seem to have a loop with your code..

i.e.

B4X:
ScrollView1.Panel.Height = 200dip * Bitmaps.Size 'Set the inner panel height according to the number of images.

For i = 0To Bitmaps.Size - 1

Dim iv AsImageView'create an ImageView for each bitmap 

iv.Initialize("") 'not interested in any events so we pass empty string.Dim bd AsBitmapDrawable
 bd.Initialize(Bitmaps.Get(i))
 iv.Background = bd 'set the background of the image view.

'add the image view to the scroll bar internal panel. 

ScrollView1.Panel.AddView(iv, 5dip, 5dip + i * 200dip, ScrollView1.Width - 10dip, 190dip)

Next


The key here for you is the third value sent to the AddView. You need to set the 200dip, to the height of your image and this also potentially points out another issue for you, in that you aren't using DIP to size your images, so maybe they look squashed for that reason? It's a bit hard to know, without seeing more of the code or a screenshot of your output.
 
Upvote 0

anallie0

Active Member
Licensed User
Longtime User
now I have modified the code and it works.

B4X:
Case "            FILETTATURA"
            immagine = LoadBitmap(File.DirAssets, "titolo metrica fine.png")
            imagetitolo.Height=immagine.Height*1.5
            imagetitolo.Bitmap = immagine
                immagine=LoadBitmap(File.DirAssets, "metrica fine.png")
                imagenumeri.Height = immagine.Height*1.5
                imagenumeri.Bitmap = immagine
                scrollimage.SetLayout(0%x, imagetitolo.Height, 100%x, 100%y)
                scrollimage.Panel.Height=imagenumeri.Height+imagetitolo.Height
 
Upvote 0
Top