Layouts in scrollview

henry1311

Member
Licensed User
Longtime User
ITALIANO
Un saluto a tutti.

Leggendo i vari post di questo forum mi sono scritto una 'sub' per visualizzare n layout all'interno di una unica scrollview.
Una specie di emulazione dello standard 'preferences' di Android, con la possibilità di utilizzare tutte le viste, gestendole come se fossero in un unico layout.

1) come posso conoscere quanto è l'effettiva altezza, occupata dalla vista posta più in basso, di ciascun layout?
Es.: button - Top=100, Height=50 dovrei sapere che l'ultima vista è a 150y
Nell'esempio allegato dovrei modificare le righe 191 e 166 in modo da sostituire il numero costante 60 con la reale altezza della vista.

2) non riesco a convertire la sub AddLayoutToSV(...) in una sub pubblica o inserita in un modulo in modo da poterla richiamare da diverse activity.
Mi date una dritta?

L'utilizzo della sub è commentato all'interno del codice.

Grazie
Enrico

----------

ENGLISH (Translated with google...!)

Greetings to all.

Reading the various posts on the forum I wrote a 'sub' to display n layout within a single Scrollview.
A kind of emulation of the standard 'preferences' of Android, with the possibility to use all the views, managing them as if they were in a single layout.

1) How can I know what is the actual height, occupied by the view put below, each layout?
Ex: button - Top = 100, height = 50 I know that the last view is 150y
In the attached example I should change the lines 191 and 166 in order to replace the costant number 60 with the actual height of the view.

2) I can not convert the sub AddLayoutToSV (...) or inserted in a public sub in a module so you can call up different activity.
Give me a tip?

The use of sub is commented in the code.

thanks
Henry
 

Attachments

  • ScrollViewNLayouts1.zip
    22.5 KB · Views: 177

stefanobusetto

Active Member
Licensed User
Longtime User
you can loop through panels
computing what you need

B4X:
Dim h As Int
h = 0
For i = 0 To scvMain.Panel.NumberOfViews - 1   
    Dim v As View
   v = scvMain.Panel.GetView(i)
   
   If v Is Panel Then
      Dim p As Panel
      p = v
      h = h + p.Height
   End If
Next
Msgbox ( "height=" & h , "dialog" )
 
Upvote 0

stefanobusetto

Active Member
Licensed User
Longtime User
create a code module called test
B4X:
'Code module
'Subs in this code module will be accessible from all modules.
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 add_view ( pnl As Panel , v As View , l , t , w , h As Int )
pnl.AddView(v, l, t, w, h)
End Sub

then replace
B4X:
scvMain1.Panel.AddView(pnl, 0, totTop, 100%x, utop)
with
B4X:
test.add_view (scvMain1.Panel , pnl, 0, totTop, 100%x, utop)

obviously in the final version put all the code of AddLayoutToSV
in the code module

ciao
 
Last edited:
Upvote 0

henry1311

Member
Licensed User
Longtime User
ITALIANO
Molte grazie stefano per le risposte.

Nella primo caso non mi ero spiegato bene.
La domanda è :
layout : sample.bal 32x480, con 2 bottoni.
Il primo posizionato a left=0, top=0, height=50, width=100
Il secondo posizionato a left=0, top=130, height=60, width=100

Mi serviva conoscere l'altezza reale del layout, considerando che nel panel (del codice allegato) ci inglobo l'intero layout.
Risultato = top_ultimo_bottone + height_ultimo_bottone = 190

quindi al codice postato era sufficiente aggiungere la riga :

uheight=pnl.GetView(i).Height che sommata al pnl.GetView(i).Top mi restituisce l'effettiva altezza del layout.
Non so perchè non ci avevo pensato prima!!! :)

Per la seconda domanda il mio problema nel mettere in un code module è che nella sub del modulo si deve fare riferimento ad una vista posta in una activity. Nel code module non posso far riferimento a oggetti dell'activity. Credo!
io vorrei fare :
modf.AddLayoutToSV(scvMain, "aempty", False, "xxx", Colors.Red, Colors.White)
modf=code module



ENGLISH

Many thanks to Stefano for the answers.

In the first case I had not explained it well.
The question is:
Layout: sample.bal 32x480, with 2 buttons.
First placed in left = 0, top = 0, height = 50, width = 100
Second plaved in left = 0, top = 130, height = 60, width = 100

I needed to know the actual height of the layout, whereas in panel (code attached) we incorporated the entire layout.
Result = top_last_button + height_last_button = 190

then the code was posted just add the line:

uheight = pnl.GetView(i).Height that added to the pnl.GetView(i).Top returns the effective height of the layout.
I do not know why I had not thought of before! :)

For the second question my problem in putting in a code module that is in the sub module is to be referred to a view puts in a activity. In the code module can not refer to objects of Activity. I believe!
I would like to do:
modf.AddLayoutToSV (scvMain, "aempty", False, "xxx", Colors.Red, Colors.White)
modf = code module

Ciao
Enrico
 
Upvote 0
Top