Android Question CLV Animated

MarcoRome

Expert
Licensed User
Longtime User
Hi All.
i have this code (example in attached) which has a horizontal clv, i would like when you go from one item to another to give an animated effect that shows that you go from one part of the item to the other as in the movie.
However, as you can see, it is not precise when the range of items changes, the effect starts from the top instead of coming from the last item chosen.
Any suggestion ??
Thank you
Marco


20221005_162343_edited.gif


B4X:
#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.
    Private xui As XUI
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    Private clv As CustomListView
    Private lbl_descrivi As B4XView
    
    'Per Resize
    Private MeasurementCanvas As B4XCanvas
    Private fnt As B4XFont
    Private Gap As Int = 7dip
    
    Dim pIndex As Int
    Dim index_Scroll As Int
    Private lbl_effetto As B4XView
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Layout")
    
    Dim lista As List
    lista.Initialize
    lista.Add("Medicina Generale")
    lista.Add("Medicina Estetica Viso")
    lista.Add("Tutti")
    lista.Add("Medicina e Chirugia Intima")
    lista.Add("Dermatoligia Estetica")
    
    lbl_effetto.Visible = False
    
    For i = 0 To lista.Size - 1
        clv.Add(CreateCategorie(xui.Color_ARGB(150,202,184,130), lista.Get(i), i),"")
    Next
End Sub



Sub clv_ItemClick (index As Int, Value As Object)
    CustomListView_Clear    'resets the prevously selected panel colors to white

    pIndex = index
    
    
    Dim indice As Int
    
    indice = index - index_Scroll
    
    Dim pnl As B4XView
    pnl = clv.GetPanel(index)
    Dim label As B4XView
    label = pnl.GetView(0)
    
    
    lbl_effetto.Visible = True
    
    'Se orizzontale
    lbl_effetto.SetColorAndBorder(xui.Color_ARGB(150,202,184,130),1dip, xui.Color_Transparent, 5dip)
    lbl_effetto.SetLayoutAnimated(400, label.Width * indice, 3dip , label.Width, label.Height)
    Sleep(400)
    lbl_effetto.Visible = False
    label.SetColorAndBorder(xui.Color_ARGB(150,202,184,130),1dip, xui.Color_Transparent, 5dip)
End Sub


Sub clv_ScrollChanged (Offset As Int)
    Log("OFFESET")
    'Log(Offset)
    lbl_effetto.Visible = False
    'lbl_effetto.SetLayoutAnimated(0, 3dip, 3dip, clv.AsView.Width, 0)
End Sub

Sub clv_VisibleRangeChanged (FirstIndex As Int, LastIndex As Int)
'    Log("First: " & FirstIndex)
    index_Scroll = FirstIndex
End Sub


Sub CustomListView_Clear
    If pIndex >= 0 Then
        Dim pnl As B4XView = clv.GetPanel(pIndex)
        Dim etichetta_das_colorare As B4XView = pnl.GetView(0)
        etichetta_das_colorare.Color = xui.Color_White
        etichetta_das_colorare.TextColor = xui.Color_Black

    End If
End Sub




'Larghezza si adatta in automatico
Sub CreateCategorie( colore As Int, categorie As String, riga As Int  ) As Panel

    Dim p As B4XView = xui.CreatePanel("p")
    p.SetLayoutAnimated(0, 0, 0, 1dip, 1dip) 'set the size before the layout is loaded
    
    p.LoadLayout("layout_clv")
    
'    If Starter.darkelight = "dark" Then
'        lbl_categoria.TextColor = xui.Color_White
'        lbl_categoria.SetColorAndBorder(xui.Color_Transparent,1dip, xui.Color_White, 5dip)
'    End If

    lbl_descrivi.Text = $"  ${categorie}  "$
    If riga = 0 Then
        'lbl_descrivi.SetColorAndBorder(xui.Color_ARGB(150,202,184,130),1dip, xui.Color_Black, 5dip)
        lbl_descrivi.SetColorAndBorder(colore,1dip, xui.Color_Transparent, 5dip)
    End If
    
    Log(lbl_descrivi.Text)
    
    MeasurementCanvas.Initialize(p)
    Dim p1 As B4XView = p.GetView(0)
    Dim xlbl As B4XView = lbl_descrivi
    fnt = xlbl.Font

    Dim TextWidth As Int = MeasurementCanvas.MeasureText(lbl_descrivi.Text, fnt).Width
    Dim Width As Int = TextWidth + Gap * 2

    p.SetLayoutAnimated(0, 1dip, 1dip, Width, 40dip)
    p1.Width = TextWidth + 10dip
    
    Return p
End Sub
 

Attachments

  • CategorieEffetto.zip
    11.4 KB · Views: 72
Top