Android Question [SOLVED] Simple animation...how to achieve (.SetLayoutAnimated)

Batman_

Member
Licensed User
Please be gentle I am a beginner and have really never done any work with animation.


1. If I want to have the appearance of some imageviews (could be pictures but dependent on app could be buttons) sweeping in from the left onto the center of the screen what is the best approach (see image: https://photos.app.goo.gl/BosonHX3npZvjN6z5)? They will also appear to sweep off the screen depending on user interaction.


2. Any suggestion on the best library to use?

In the diagram I want the appearance of some scrolling text.
3. Is an animated gif a good idea? (See image: https://photos.app.goo.gl/BosonHX3npZvjN6z5)
4. Is there a better alternative to an animated gif?

Sorry for the simple questions but animation is really a new concept for me and seems essential for mobile apps as appearance is very important.
 
Last edited:

Batman_

Member
Licensed User
Hi.

I have made some progress but cannot get the co-ordinates to send the imageview to the center of the screen correctly. I am trying to send the imageview from the top left of screen to the center of the screen. This is my code:

B4X:
    Dim iLeft As Int
    Dim iTop As Int
    
    iLeft = Activity.Width/2
    iTop = Activity.Height/2
        
    'Move to start position
    imageviewAnswerStatus.Visible=False
    imageviewAnswerStatus.SetLayoutAnimated(0, 0, 0, imageviewAnswerStatus.Width, imageviewAnswerStatus.Height)
        
    If correctYN="Y" Then
        imageviewAnswerStatus.SetBitmap(xui.LoadBitmapResize(File.DirAssets, "Correct01.PNG", imageviewAnswerStatus.Width, imageviewAnswerStatus.Height, True))
    Else
        imageviewAnswerStatus.SetBitmap(xui.LoadBitmapResize(File.DirAssets, "Wrong01.PNG", imageviewAnswerStatus.Width, imageviewAnswerStatus.Height, True))

    End If

    'Move to new position...ensure visible to user
    imageviewAnswerStatus.Visible = True
    imageviewAnswerStatus.SetLayoutAnimated(600, iLeft, iTop, imageviewAnswerStatus.Width, imageviewAnswerStatus.Height)
    imageviewAnswerStatus.BringToFront
This is where the imageview ends up (see screenshot). Can somebody please assist with getting the co-ordinates for:
Left; and
Top;

to use in .SetLayoutAnimated().

Regards.
 

Attachments

Brandsum

Well-Known Member
Licensed User
B4X:
Dim newLeft as int = 50%x - (imageviewAnswerStatus.Width/2)
Dim newTop as int = 50%y- (imageviewAnswerStatus.Height/2)

imageviewAnswerStatus.SetLayoutAnimated(600, newLeft, newTop, imageviewAnswerStatus.Width, imageviewAnswerStatus.Height)
 
Top