Property animation in android < 3.0 - android

Is there an easy way to implement property animation(e.g. animate "x" or "y" property from value1 to value2) in android < 3.0? I need to animate a visual control(Button or TextView), that needs to handle click events(so, drawable animation is not appropriate).
Update:
So, there is a lot of games with animation(Cut the Rope, etc.). How these game developers solved the problem? What the way they use for animation?

I know this is an old thread, but for those who stumble across this in a Google search, there is a compatibility library available that gives you access to the property animations introduced with Honeycomb all the way back to Android 1.0.
I've used it for some small things, and it works like a charm. http://nineoldandroids.com/

Afaik, for this to work you have to roll your own animation framework first that interpolates the values the way you'd like. Then, you could animate e.g. the margin property of the button with this framework, calling .setLayout() on every tick. This causes the ui-framework to relayout/redraw the whole screen, with the new margin value.
However, this is a terribly slow and wasteful way to animate and I don't recommend it. There might be better solutions.

Related

Animate Fab Button cross to mark

In my Android application I want to have a Floating Action Button to display a success state. I would like to have something like in the picture below:
But I have no idea how to animate the cross to the mark. Can someone please explain to me how I can do that? Is there maybe a library or something like that? Atm I'm using the default FAB from the design library.
This question got me interested in checking out AnimatedVectorDrawable, so I went ahead and made a small sample app that will achieve a similar animation, on github here.
Bad quality gif here.
Couple things to note: minimum SDK is set to 23 to make use of AnimationCallbacks for starting the 2nd animation, but you can achieve the same result using a Handler.postDelayed() with your animation durations to handle the drawable change and animation start. Since AnimatedDrawableCompat does not support path morphing, I needed two drawables to get the two different images.
Should be compatible with the Support Library AnimatedVectorDrawableCompat if you choose to use it as well.

Android - animating views in xml

I searching for a way to animate views via xml, I am really lost in this part of UI programming.
Can anybody explain to me step by step how to do this?
You can animate android views by using Animation resources.
With xml animations you can set different properties e.g duration, rate of change (interpolator).
AndroidHive has a very good tutorial with a nice set of animations
http://www.androidhive.info/2013/06/android-working-with-xml-animations/
From my experience with xml animations, you won't know what you want until you've played around with different properties.
http://developer.android.com/guide/topics/resources/animation-resource.html
Update:
Interpolators as well are also important,they allow you to achieve a lot more smoothness. But misusing them can also be expensive so be make sure its necessary.
http://developer.android.com/reference/android/view/animation/Interpolator.html
This blog also gives a quick peek into the actual effects of interpolators:
http://android-er.blogspot.co.uk/2012/02/various-effect-of-interpolator-in.html

View Animations alternatives for API<11

This google API tutorial shows how to animate Views. However it uses methods that are available from API level 11, such as View.setAlpha
Now, using a phone with android 2.1 (API 7) I can find many , many applications using the same kind of animations (the card flip animation is very popular)
Are there any Google libraries to do the animations shown in this tutorial that would work with ANY API prior to 11?
If not, any other alternatives?
P.S I am aware of this question But appearantly that was specifically about objectanimator and got an unuseful anser accepted
NineOldAndroids will be able to provide you with animation APIs that you see in 11+. For example...
ViewHelper.setAlpha(view, 0);
Easy animation such as transform, rotate, move (which it seems to be what you want) may be made with such classes as:
http://developer.android.com/reference/android/view/animation/AnimationUtils.html
http://developer.android.com/reference/android/animation/AnimatorSet.html
http://developer.android.com/reference/android/view/animation/Animation.html
In brief you will have create animation resources (or classes) and run it on views. After ending animation possibly you will have hide this view by visibility method.
Check this for details - http://jmsliu.com/779/android-view-animation-example.html.

android setAlpha slow

If I do setAlpha(0.5f) on a few (image) views, my app gets horribly slow, at least on my Android 4.+ tablets.
If I remove the setAlpha calls, the app (scrolling and paging) works smoothly.
Is there an alternative/faster method for making my views semitransparent?
If you provide some code I can try to see what is wrong, there is no reason and explanation of slowing the app, there must be other thing in the code/project/layouts to make your app work slower
Try creating a custom view that calls Canvas.saveLayerAlpha() before drawing its children. Android 3.0+ versions there is a View.setAlpha() api..
Also you can create transparent or opaque background.Here is the link
http://zaman91.wordpress.com/2010/03/22/android-how-to-create-transparent-or-opeque-background/
Hope it helps.

Does the android:clipChildren still works?

Does the android:clipChildren still works?
I have a AbsoluteLayout with a size and set the clipChildren to false. When I add childeren that are bigger then the AbsoluteLayout the childeren are still clipped.
Anyone got this working?
Working with Android 2.2 (API level 8)
Update 20-01-11:
I can make something similiar with a RelativeLayout, but does the android:clipChildren work on that?
btw, it's not needed that my application needs to work on any other platform then Android 2.2.
Absolute layout is deprecated. I suggest using something different.
This class is deprecated. Use
FrameLayout, RelativeLayout or a
custom layout instead.
http://developer.android.com/reference/android/widget/AbsoluteLayout.html
Edit: Answering to your comment:
Being deprecated means that for some reason, they stopped developing it. Maybe there's a better replacement, maybe they don't like the way it works. Anyway, they may drop this layout in future versions (which means your app won't be able to run in a future version of android).
Alternatives:
Frame Layout:
FrameLayout is designed to block out
an area on the screen to display a
single item. You can add multiple
children to a FrameLayout, but all
children are pegged to the top left of
the screen. Children are drawn in a
stack, with the most recently added
child on top. The size of the frame
layout is the size of its largest
child (plus padding), visible or not
(if the FrameLayout's parent permits).
Views that are GONE are used for
sizing only if
setConsiderGoneChildrenWhenMeasuring()
is set to true.
http://developer.android.com/reference/android/widget/FrameLayout.html
Relative Layout
You can also use a relative layout. Align every view by it's parent and set left and top margins as you wish. This may be your best option IMO. I've done this before and it worked reasonably well.
As Pedro said, this feature may have been an addition that came after AbsoluteLayout's deprecation, so if it's not implemented already, it will never work.
As far as the comment "which means your app won't be able to run in a future version of android", Google has promised that this will NEVER be the case.
Dianne Hackborn
On Mon, May 4, 2009 at 10:00 AM,
Sundog wrote:
I have a highly rated app that simply... could... not... be...
written... without AbsoluteLayout, no matter whose Java sensibilities
it steps on. I guess Android's doing so well with apps that it can
afford to shut down an entire category of games.
Did AbsoluteLayout disappear from 1.5?
No. Are you unable to write 1.5 apps
using it? No. Have we ever said we
have any plan to completely remove it
at any point in the future? No. You
need to find better reasons to be a
victim. If you can't find one, let
us know the name of your app and we
can make sure to break it in the next
release. Then you can -really-
complain!
-- Dianne HackbornAndroid framework engineerhack...#android.com
and later:
I'll say again: we are not going to
remove AbsoluteLayout from a future
release, but we strongly discourage
people from using it.
I'd say it's a safe bet to say it won't be removed, but it also won't get new features/fixes either.

Categories

Resources