Android Question animate clv items (slide down)

ilan

Expert
Licensed User
Longtime User
hi

i would like to animate clv items so when i click on an item it will slide smoothly down to the end of the list. what would be the best way to do that.

what i do now is storing all items in a list using custom types and then i do the animation when i click on an item and then recreate the list completely so clear and create again. it works fine using few items (tested with 30) but i am not sure i should recreate the clv again.

what do you think?


EDIT: my list will not have a lot items, i guess max 50 but still i am not really happy with the solution.
 

LucaMs

Expert
Licensed User
Longtime User
I think is possible to move an item without the need to recreate all items.
You should create a new method in CLV (xCustomListView) in which you get the base panel of the item, apply SetLayoutAnimated to move the item, a timer with the same duration and in the tick event "adapt" some indexes (but I have to study well this important last thing).

The "author of xCustomListView" :) could do it better than me and especially in shorter times
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
If you are using the old CustomListView then you should switch to xCustomListView.
Make CLV.GetItem a public sub.

This code will remove an item from the list, add it to the ScrollView, animate it to the bottom and then add it back to the list:
B4X:
Sub clv1_ItemClick (Index As Int, Value As Object)
   Dim item As CLVItem = clv1.GetItem(Index)
   Dim p As B4XView = clv1.GetPanel(Index)
   p.RemoveViewFromParent
   p.Color = item.Color
   If Bit.And(0xff000000, item.Color) = 0 Then
       p.Color = xui.Color_Gray
   End If
   clv1.RemoveAt(Index)
   clv1.sv.ScrollViewInnerPanel.AddView(p, 0, item.Offset, clv1.sv.Width, p.Height)
   Dim Duration As Int = 1000
   p.SetLayoutAnimated(Duration, 0, clv1.GetItem(clv1.LastVisibleIndex).Offset + 100dip, p.Width, p.Height)
   Sleep(Duration)
   p.RemoveViewFromParent
   p.Color = item.Color
   clv1.Add(p, item.Value)
   Sleep(0)
   clv1.ScrollToItem(clv1.Size - 1)
End Sub
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
If you are using the old CustomListView then you should switch to xCustomListView.
Make CLV.GetItem a public sub.

This code will remove an item from the list, add it to the ScrollView, animate it to the bottom and then add it back to the list:
B4X:
Sub clv1_ItemClick (Index As Int, Value As Object)
   Dim item As CLVItem = clv1.GetItem(Index)
   Dim p As B4XView = clv1.GetPanel(Index)
   p.RemoveViewFromParent
   p.Color = item.Color
   If Bit.And(0xff000000, item.Color) = 0 Then
       p.Color = xui.Color_Gray
   End If
   clv1.RemoveAt(Index)
   clv1.sv.ScrollViewInnerPanel.AddView(p, 0, item.Offset, clv1.sv.Width, p.Height)
   Dim Duration As Int = 1000
   p.SetLayoutAnimated(Duration, 0, clv1.GetItem(clv1.LastVisibleIndex).Offset + 100dip, p.Width, p.Height)
   Sleep(Duration)
   p.RemoveViewFromParent
   p.Color = item.Color
   clv1.Add(p, item.Value)
   Sleep(0)
   clv1.ScrollToItem(clv1.Size - 1)
End Sub


Thanx a lot erel i will try it out (this code looks really interesting.) :)
 
Upvote 0
Top