iOS Question Height with "SetLayoutAnimated" will not be animated

Mike1970

Well-Known Member
Licensed User
Hi i found out that if i set an Height using setlayoutanimated to increase, it works..
but if i want to decrease, that will not be animated.

This is the function that i call when i click on a panel (where inside there is the green label)
B4X:
Sub CheckCibo(parent As B4XView, Index As Int)
    Dim p As Panel = parent.GetView(Index)
    Dim l As Label = p.GetView(1)
   
    If l.Top = 0 Then    ' Deselect - It means that the label is filling the whole panel
        l.SetLayoutAnimated(5000, 1, 0, l.Tag, l.Width, p.Height - l.Tag) 'so, i want to bring it back to its normal state (in l.tag is stored the normal .Top value) - THIS NOT WORKS
    Else    ' Select
        l.SetLayoutAnimated(5000, 1, 0, 0, l.Width, p.Height) 'else I want to fill the whole panel with the label - THIS WORKS PROPERLY
    End If
End Sub

ezgif.com-resize.gif
 

Mike1970

Well-Known Member
Licensed User
upload an example to review.

Ok i made an example of the problem, i attached it.


If you are setting it to zero size then it will animate an empty snapshot.
The height is never set to "0", it can be The parent.height or another value > 0.

What's the proper way to show the animation in the correct way?
 

Attachments

  • animationtest.zip
    2.5 KB · Views: 87
Upvote 0

Omar Parra A.

Expert
Licensed User
Longtime User
Note: Use Label1.Height

test:
global:
Dim h As Int

Initialize:
h = Label1.Height

B4X:
Sub Button1_Click
    If h = Label1.Height Then
        Label1.SetLayoutAnimated(2000, 0, 0, Panel1.Width, Panel1.Height)
    Else 
        Label1.SetLayoutAnimated(2000, 0, Panel1.Height - h, Panel1.Width, h)
    End If
End Sub
 

Attachments

  • 1.gif
    1.gif
    32.4 KB · Views: 90
Last edited:
Upvote 0

Mike1970

Well-Known Member
Licensed User
Note: Use Label1.Height

test:
global:


Initialize:


B4X:
Sub Button1_Click
    If h = Label1.Height Then
        Label1.SetLayoutAnimated(2000, 0, 0, Panel1.Width, Panel1.Height)
    Else
        Label1.SetLayoutAnimated(2000, 0, Panel1.Height - h, Panel1.Width, h)
    End If
End Sub

I tried this solution but I get the same behavior... :(
can you post your project? I really don't understand why it not works ... I think the code it's correct.


B4X:
Sub Process_Globals
    Public App As Application
    Public NavControl As NavigationController
    Private Page1 As Page
    Private xui As XUI
    Private Label1 As B4XView
    Private Panel1 As B4XView
    Dim h As Int
End Sub

Private Sub Application_Start (Nav As NavigationController)
    NavControl = Nav
    Page1.Initialize("Page1")
    Page1.RootPanel.LoadLayout("Page1")
    NavControl.ShowPage(Page1)
   
    h = Label1.Height
End Sub

Sub Button1_Click
    If h = Label1.Height Then
        Label1.SetLayoutAnimated(2000, 0, 0, Panel1.Width, Panel1.Height)
    Else
        Label1.SetLayoutAnimated(2000, 0, Panel1.Height - h, Panel1.Width, h)
    End If
End Sub
 
Last edited:
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Tip: prefer using B4XViews instead of the native type. This way your code will be cross platform.

The issue is related to the way the OS optimizes labels as lightweight views. Put the label inside a panel and animate the panel:
B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'Public variables can be accessed from all modules.
    Public App As Application
    Public NavControl As NavigationController
    Private Page1 As Page
    Private xui As XUI
    Private Label1 As B4XView
    Private Panel1 As B4XView
    Private pnlLabel As B4XView
End Sub

Private Sub Application_Start (Nav As NavigationController)
    NavControl = Nav
    Page1.Initialize("Page1")
    Page1.RootPanel.LoadLayout("Page1")
    
    NavControl.ShowPage(Page1)
    Log(pnlLabel.Top)
    pnlLabel.Tag = pnlLabel.Top    ' I save the current Top value (normal state)
End Sub

Sub Button1_Click
    If pnlLabel.Top == 0 Then    ' If is 0 it means that the label is already "full size"
        pnlLabel.SetLayoutAnimated(2000, pnlLabel.Left, pnlLabel.Tag, pnlLabel.Width, Panel1.Height - pnlLabel.Tag)
    Else    ' else it means it is in "normal state", so i expand it
        pnlLabel.SetLayoutAnimated(2000, pnlLabel.Left, 0, pnlLabel.Width, Panel1.Height)
    End If
End Sub
 

Attachments

  • animationtest.zip
    2.6 KB · Views: 87
Upvote 0

Mike1970

Well-Known Member
Licensed User
Tip: prefer using B4XViews instead of the native type. This way your code will be cross platform.

The issue is related to the way the OS optimizes labels as lightweight views. Put the label inside a panel and animate the panel:
B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'Public variables can be accessed from all modules.
    Public App As Application
    Public NavControl As NavigationController
    Private Page1 As Page
    Private xui As XUI
    Private Label1 As B4XView
    Private Panel1 As B4XView
    Private pnlLabel As B4XView
End Sub

Private Sub Application_Start (Nav As NavigationController)
    NavControl = Nav
    Page1.Initialize("Page1")
    Page1.RootPanel.LoadLayout("Page1")

    NavControl.ShowPage(Page1)
    Log(pnlLabel.Top)
    pnlLabel.Tag = pnlLabel.Top    ' I save the current Top value (normal state)
End Sub

Sub Button1_Click
    If pnlLabel.Top == 0 Then    ' If is 0 it means that the label is already "full size"
        pnlLabel.SetLayoutAnimated(2000, pnlLabel.Left, pnlLabel.Tag, pnlLabel.Width, Panel1.Height - pnlLabel.Tag)
    Else    ' else it means it is in "normal state", so i expand it
        pnlLabel.SetLayoutAnimated(2000, pnlLabel.Left, 0, pnlLabel.Width, Panel1.Height)
    End If
End Sub

Ok thanks!
However, this was the text will not be vertically centered in the panel :( it maintains the position based on the starting value.. ignoring the fact that the parent is resizing. I tried to set all anchor points in the designer but it seems to not be affected.

It shows like this:
ezgif.com-resize.gif



instead, I need something like this (done by dragging the things in the designer):
ezgif.com-resize.gif


it's this the critical point of my problem :(


EDIT:
I found out that doing like this i can achieve the result i want. Is there some contraindication by doing like so?
B4X:
Sub Button1_Click
    If pnlLabel.Top == 0 Then    ' If is 0 it means that the label is already "full size"
        pnlLabel.SetLayoutAnimated(2000, pnlLabel.Left, pnlLabel.Tag, pnlLabel.Width, Panel1.Height - pnlLabel.Tag)
    Else    ' else it means it is in "normal state", so i expand it
        pnlLabel.SetLayoutAnimated(2000, pnlLabel.Left, 0, pnlLabel.Width, Panel1.Height)
    End If
    Label1.SetLayoutAnimated(2000, Label1.Left, 0, Label1.Width, pnlLabel.Height) 'Animate the label too at the same time
End Sub
 
Upvote 0
Top