Android Example Animation without timer

Hi Guys

I would like to share with you something that most of you maybe allready know but also if there are some people that still dont know that, it could be very helpfull for them.

There are lots of ways to animate something or scale, translate, resize ... views
i will show you a simple way to resize a panel without a timer only with a simple code (you can also
animate or do other stuff with this solution)

code:

B4X:
#Region  Project Attributes
    #ApplicationLabel: B4A Example
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: false
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
Dim p As Panel
Dim b1 As Button

End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")

    b1.Initialize ("b1") 'intialize button
    b1.Text = "Click Me"
    p.Initialize ("p") 'intialize panel
    p.Color  = Colors.White
    Activity.AddView(p,10dip,10dip,200dip,100dip) 'add panel to actvity
    Activity.AddView(b1,10dip,Activity.Height - 100dip,100dip,100dip) 'add button to actvity



End Sub

Sub b1_click
    doanimation(p,200dip,200dip,100dip,100dip) 'start resize
End Sub

Sub Activity_Resume

End Sub

Sub doanimation(selp As Panel,maxw As Int, maxh As Int,minw As Int, minh As Int)
        If selp.Height >= maxh Then
            Do Until selp.Height <= minh
                selp.Height = selp.Height - 5dip
                DoEvents
            Loop
        Else
            Do Until selp.Height >= maxh
                selp.Height = selp.Height + 5dip
                DoEvents
            Loop
        End If
End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub


regards, :)
 

Attachments

  • animation without timer.zip
    224.4 KB · Views: 1,919
Last edited:

barx

Well-Known Member
Licensed User
Longtime User
Seems though this just uses a loop and the do events, am I right in assuming the animation will run at differing speeds depending on device spec?
 

ilan

Expert
Licensed User
Longtime User
Yes exactly. Its uses only the loop, and the do events, and if you need small animation its a very simple and clean way to do it instead of putting lots of timers,..

What importent is, is to use the changing pixels depends on the activity hight and not like i wrote

... + 5dip

I just wrote an example but if you want a similar animation to any screen size use a calculate value
 

ilan

Expert
Licensed User
Longtime User
i am using it erel, and also from informatix "Animation Plus" both are very good libraries

this code is only to expand general knowledge :)
 

LucaMs

Expert
Licensed User
Longtime User
Can someone help me with making text in a label scroll from left to right?

As someone would answer, you should open a new thread.

Probably there are libraries, to do it (you can search) but you could simply use a HorizontalScrollView, putting a label in its inner panel. If you want to scroll the label manually, put a transparent panel on the label and use its events where you will change the HSV panel position.
 

anaylor01

Well-Known Member
Licensed User
Longtime User
Maybe I didn't explain myself correctly. I want the label to move across the screen.So the text looks like it is floating across the screen. I was thinking something like the following.
B4X:
'                       Dim pf As Int
'                       For pf = 1 To 400
'                           lblPointFlash.Left = lblPointFlash.Left + pf
'                    Next
 
Top