Android Tutorial Android views animation tutorial

enrique1

Member
Licensed User
Longtime User
Stop Animation

Hi,

A question: I want to do a rotate animation, but when the animation has finished, the view return to the originial position.

What can I do to set the final view position??

Thx!
 

enrique1

Member
Licensed User
Longtime User
Ok

Hi,

A question: I want to do a rotate animation, but when the animation has finished, the view return to the originial position.

What can I do to set the final view position??

Thx!

Ok.. Sorry, I answer to myself reading again:

Originally Posted by Erel:
For now you can't keep it rotated.
You can use the Canvas object to draw rotated bitmaps and rotated drawables.

I'll try to set the new position with EndAnimation event.
 
Last edited:

enrique1

Member
Licensed User
Longtime User
Ok.. Sorry, I answer to myself reading again:



I'll try to set the new position with EndAnimation event.


And sorry, could you write the EndAnimation event?

Something like this?:

¿¿ Sub eventName_EndAnimation
End Sub
??
 

Widget

Well-Known Member
Licensed User
Longtime User
B4X:
Sub Animation_AnimationEnd
    If Sender = a6 Then
        a7.Start(Button6)
    Else If Sender = a7 Then
        a8.Start(Button6)
    Else If Sender = a8 Then
        a9.Start(Button6)
    End If
End Sub

This AnimationEnd works fine for animating a few views. But I am animating 50 objects and each object may have 5 or 6 animations. I have two lists, lstView that contains a type structure describing the object, and this structure has another list called lstAnim that contains the animations that this View will go through.

When an animation ends, how can I easily determine which View the animation belongs to? The Sender in _AnimationEnd is Animation and there is no Animation.Tag property so I can't point back to the View that was animated. The only thing I can think of is to have two nested loops. The first loop traverses through lstView and for each lstView entry then loop through each lstAnim looking for Sender. I don't know if this will be fast enough. Is there a faster way to find the View for Sender inside of _AnimationEnd?

Widget

Hint: It would be nice if Animation had a View or Parent property so I could easily know what was being animated.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Hint: It would be nice if Animation had a View or Parent property so I could easily know what was being animated.
I agree, however it is technically not possible due to the way that the native Animation objects work.

You can create a Map object that will store the animations as keys and the views as values. It will allow you to easily find the view.
 

Widget

Well-Known Member
Licensed User
Longtime User
Erel,
I took your advice and used a Map (for the first time) and it worked like a charm. Many thanks. It didn't occur to me a Map could index an object (very neat) because I thought it was restricted to only strings and numbers.

I have a question that is more related to Lists/Maps but also concerns Animations, so I thought I'd ask it here. I have a List that I add Animation objects to using something like:

B4X:
sub Globals
  dim lstAnims as List
  lstAnims.Initialize
end sub

Sub Define_Anim
  lstAnims.Clear            'IS THIS HOW I CLEAR THE OLD ENTRIES?
  dim LocAnimation as Animation
  locAnimation.InitializeTranslate(...)
  lstAnims.Add(locAnimation)
     .... ' A dozen animations can be added here
  dim LocAnimation as Animation
  locAnimation.InitializeTranslate(...)
  lstAnims.Add(locAnimation)
end sub

sub Button6_Click
  Define_Anim
  dim LocAnimation as Animation
  LocAnimation = lstAnims.Get(0)
  LocAnimation.Start(Button6)
end sub

When I use Delphi I have to remember to clear the old objects that I've created and added to a list whenever the list is reused or when the list is disposed of. B4A doesn't seem to have this constraint. So my question is, when & how do I release the LocAnimation that was created and added to lstAnims in Define_Anim?

1) Do I simply clear the list using lstAnims.Clear?
2) Or do I have to use lstAnims.Initialize?
3) Or do I have to destroy each locAnimation that was added to lstAnims (like I would in Delphi)?

The Button6_Click could be run dozens of times (or in a continuous loop), and I want to make sure I free up the previously allocated memory (locAnimation) before starting a new list of animations. Like I said earlier, this question applies to any object added to a list or map, not just the Animation object.

Can you shed some light on freeing or releasing memory for objects that have been added to a list/map and are no longer needed?

TIA
Widget
 

Gigatron

Member
Licensed User
Longtime User
You are very great men Erel ' have not changed )

With my bad english a have read all post about anim, and found the solution.

'anim win
B4X:
   animwin.InitializeAlpha("", 1, 0)
   animwin.Duration = 1500
    animwin.RepeatCount = 0
    animwin.RepeatMode = animwin.REPEAT_REVERSE



Sub animwin_AnimationEnd
   animwin.Stop(pic1)
End Sub



Thanks alot again Erel

GTR
 
Last edited:

walterf25

Expert
Licensed User
Longtime User
Animation

Hello everyone, i was wondering if buttons are the only things that can be animated with the animation library, can we animate imageviews, etc.... if so can anyone provide me with a code sample as to how to do this, what i'm actually trying to do is load a picture of a soccer ball and have the ball rotate in one place, i know someone here created an app that does this, but i'm trying to find out how he acomplished this, if anyone can provide me in the right direction that will be very well appreciated

Thanks.
 

Gigatron

Member
Licensed User
Longtime User
Here the project , you can play with imageview animation.

Have Fun.
 

Attachments

  • ballanim.zip
    33.9 KB · Views: 802
  • ball.jpg
    7.4 KB · Views: 589

buras3

Active Member
Licensed User
Longtime User
problem with frame

hello Erel and all

i programed a game "number puzzle"
i took the animation from this tutorial

but when i put frame in the panel - the up and right sides of the frame are become black when the button is moving .

i tried to make the image smaller or put the frame in different panel - but it's still the same .

if i don't put image in the button - it's OK
but if i put image or color like the tutorial the problem with the frame come's back.

what can i do?

tank you
 

Attachments

  • Untitled.jpg
    30.6 KB · Views: 615
Last edited:

buras3

Active Member
Licensed User
Longtime User
tank you for answer

i have checked already in real device and it's the same problem
 

buras3

Active Member
Licensed User
Longtime User
project

i post my project
push play and after move some button

tanks
 

Attachments

  • Cellular.zip
    20.4 KB · Views: 597

buras3

Active Member
Licensed User
Longtime User
tank you for checking

is there no way to fix it
like redraw the frame or something?
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…