Bug? SetLayoutAnimated

LucaMs

Expert
Licensed User
Longtime User
I wanted to animate a panel, from its initial width to zero.

If you set:
B4X:
Panel1.SetLayoutAnimated(500, Panel1.Left, Panel1.Top, 0, Panel1.Height)
the panel disappears immediately, instead of do it in 500ms.

I noticed that a panel added by Designer has its border width set to 2dip.
Then you must set the minimum new width to the border width + 1dip to get the correct animation,
but if you set the new width to zero, the animation will not happen even if you set the border width to zero.

Also, even if you get the right animation, at least on my tablet with Android 4.4.2 - 1280x800 - scale 1, traces of the previous "image" remain:
1.gif



They are not so visible in the animated gif, maybe:
upload_2018-5-19_2-41-55.png



Finally, if during the animation you increase the width of the panel, its content remains visible (it too will be animated), while in the opposite direction, decreasing the width, it disappears (as you can see in the animated gif above).
1.gif






P.S. no traces on another device, Android 7 - 1920x1080 - scale 2.5
 

Attachments

  • SetLayAnim test.zip
    41.8 KB · Views: 383
Last edited:

mangojack

Well-Known Member
Licensed User
Longtime User
I am having the same issue.

A panel added with designer containing an image.
If you use SetLayoutAnimated from its current size to a width of 0 , the panel resizes instantaneously. (there is no animation)

If the new width is set to 1dip the animation takes place but the image is quickly blurred prior to resizing.

Resizing the panel back to original size animates correctly .. (with the image also resizing correctly)

* ( unlike @LucaMs .. in the designer , when adding a panel there is no default border size ?)
 

Attachments

  • SLA Test.zip
    16.6 KB · Views: 299

LucaMs

Expert
Licensed User
Longtime User
But if you set that value, then you need to set the value of the animation to that value + 1 dip.

There is a workaround (although this forces me to write extra code in a library... really not very useful):
use two animations for... each animation.

B4X:
Panel1.SetLayoutAnimated(500, Panel1.Left, Panel1.Top, 1dip, Panel1.Height)
sleep(530)
Panel1.SetLayoutAnimated(500, Panel1.Left, Panel1.Top, 0, Panel1.Height)
In my case, where you may have a variable minimum value, not always 0, I need more code.
(not tested, but something similar to this should help).



Unfortunately, I don't know workarounds for:
if during the animation you increase the width of the panel, its content remains visible (it too will be animated), while in the opposite direction, decreasing the width, it disappears

and not even for this:
traces of the previous "image" remain
 
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
This is related to the way animations are implemented. It immediately sets the view's layout to the target layout and then animates it by animating the scale and translation properties. It makes it simple to use SetLayoutAnimated as the layout state is consistent.

The view will immediately disappear if you set its target size to zero as the scale will have no effect.
 

LucaMs

Expert
Licensed User
Longtime User
This is related to the way animations are implemented. It immediately sets the view's layout to the target layout and then animates it by animating the scale and translation properties. It makes it simple to use SetLayoutAnimated as the layout state is consistent.

The view will immediately disappear if you set its target size to zero as the scale will have no effect.

Perfect, I understood ... nothing :p

I suppose there are no solutions.




About this:
traces of the previous "image" remain
since:
no traces on another device, Android 7 - 1920x1080 - scale 2.5
I suppose that the problem can be the anti aliasing (?)
 

LucaMs

Expert
Licensed User
Longtime User
I suppose there are no solutions.
There is one:

1.gif



Using NineOldAndroids :D (I hope it will work always with B4XViews; here it works).

I have to find why if I set a bitmap in an ImageView using LoadBitmapResize I get the right image but if I do it with a B4XView I get a "zoomed image"; probably Fill / Center settings stuff)
 
Last edited:
Top