I have view with several components on it. I use Linear layout with vertical orientation
When user unchecks some checkbox I need to hide one EditText and other components moves up
edtPhone.setEnabled(false);
works well, but everything happens immediately and i want to do it slowly and animated
How can i do it in android?
Create a TranslateAnimation, assign an AnimationListener to it and in onAnimationEnd() you should set the visibility of your EditText to View.GONE (or View.INVISIBLE, it depends on your needs) and do whatever you want when the animation has stopped.
Remember to assign the TranslateAnimation to the other components that should move up. In order to get your TranslateAnimation to move slowly, use android:duration in XML or Animation.setDuration() in code, with a defined value in milliseconds (maybe 500 milliseconds?).
Related
I have several EditText views that I want to animate a change in text of in succession one after the other. I would like to implement a slide out/in animation (old text slides down below and new text slides in from above).
I think this would require setting an animation listener to the slide down animation so that the slide in animation can be started when the slide down animation ends. However it seems the animation listener is attached to the animation itself whereas I need to know when an animation has ended on a particular EditText and to set the correct new text on the EditText.
Since the actual animation for each EditText will be the same, is there a way to do this with just the one animation object (i.e. Animation slideDown) or do I have to create a separate animation objects for each field (e.g. Animation slideDown1, slideDown2, slideDown3, etc)?
I have following layout:
Three EditTexts in LinearLayout with layout_width = 0.33. When user put focus to one of those EditTexts, two other should dissapear (maybe animation too) and last one should be moved to the top of the screen with some animation meanwhile soft keyboard is shown. Result should looke like this:
Solution without animation is simple:
if(focusedView == mBlueEdit) {
mRedEdit.setVisibility(View.GONE);
mGreenEdit.setVisibility(View.GONE);
I can't figure out, when to start (it's too late start it after GONE is set at other views) and how to compute X and Y positions at start and at the end of animation. Thanks in advance for every hint.
Not sure if it is what you are looking for, but you can create automatic animation by simply adding android:animateLayoutChanges="true" to your LinearLayout.
I am making a game in which I have 5 buttons, looking like clouds, falling from the "sky".
That means that when my activity starts, 'clouds' cannot be seen, since the marginTop is set to -100dp.
From that position they start falling down untill they get lost on the bottom side of the screen.
The thing is, I need those buttons to be clickable, during the process of animation.
So far, I found some documentation about how I can make the buttons clickable AFTER the animation ends. But I don't need that. I need to be able to click on the buttons through the animation time itself.
NOTE: I need something that works with versions before 3.0.
Anybody has any link to documentation or some example or anything ?
After doing some research, I found out that there are two types of animations:
View Animation and Property Animation.
The view animation can only animate View objects. It also lack a variety of animations, since it can do only stuff as scale, rotate, move... It cannot change background color, for example.
Also, the disadvantage of the View Animation is that it only change the position of where the View object is DRAWN. Physically, it still stays in the same position.
That's why the button is un-clickable, after the View Animation is finished upon it.
Property Animation, in the other hand, can animate both View and non-View objects and it doesn't have constraints as the View Animation.
When objects are moved, for example, with the property animation, they are not just drawn on some other position on the screen, but they are actually MOVED there.
Now, Property Animation is a lot more complex to write than the View Animation, so if you don't really need all the advantages of the Property Animation, it is suggested to use View Animation.
Source:
Property vs View Animation
Tutorial and SupportLybrary up to API 1:
nineoldandroids
You can change the buttons to imageViews and then do
imageView.setOnClickListener(myListener)
then set myListener to do whatever you previously wanted to happen on the buttons onClick. Your activity will have to implement OnClickListener
Added bonus: you can make the images look like clouds :)
I've got an absolute layout. In that layout is a custom view that takes up the left 3rd of the screen. I put a button in the layout that I want to cause the custom view to slide on and off of the screen. I've tried using animation resources (translates... "slidein" and "slideout") and the function startAnimation on the custom view, but I can't get the behavior I am looking for.
OK... I start with the custom view visible and in onCreate I find the view and animate it off screen using my slideout animation. That works fine. I figured out that I need to set "fillAfter" in the animation so that the custom view stays off screen.
Now, when I press my button I want to cause the custom view to slide back on the screen, so I trigger my slidein animation using startAnimation again but with slidein. BUT... that causes the view to first jump back to its original position AND THEN slide to the right... causing it to finish in the middle of the screen.
How do I get the animation to use the view's current position as the animation starting position, not its original position?
Thanks
I also experienced the flicker described in this question. My solution was to use the improved Honeycomb animation APIs. There is a convenient library that ports these all the way back to Android 1.0:
http://nineoldandroids.com/
For more on Honeycomb Animation APIs see:
http://android-developers.blogspot.com/2011/02/animation-in-honeycomb.html
In my case I had 2 overlapped LinearLayouts inside a RelativeLayout. I wanted to slide the top LinearLayout off the screen and reveal the bottom LinearLayout below. Then I wanted to slide to top LinearLayout back on screen to its original position so the top layout covered the bottom layout again. Using the old animation APIs I was seeing a flicker before the second animation (offscreen -> onscreen) was starting.
With the new APIs this task turned out to be trivial:
// Slide out (add to button handler)
ObjectAnimator.ofFloat(mTopLayout, "translationY", mTopLayout.getHeight()).start();
// Slide back in (add to button handler)
ObjectAnimator.ofFloat(mTopLayout, "translationY", 0).start();
The Honeycomb Animation APIs actually move objects around on the screen (rather than pretending to move them like the older animation APIs), so there is no need to fool around with filleAfter, fillBefore, etc.
Look into setting the fillAfter property to keep the end animation state
I am trying to swap two LinearLayouts by setting their visibility properties to "VISIBLE" and "GONE" respectively. I am also using an animation while the layouts are being swapped. The animation completes successfully and I see the correct layout. However, the previous Layout which has its visibility property set to "GONE" still receives clicks even though it's not visible. At the same time, the layout which is "VISIBLE" receives clicks only when clicked in area where the "GONE" layout isn't clickable. I am also calling the requestFocus method on the "VISIBLE" layout. But it doesn't help.
Moreover, if I skip the animation part and just set the visibility properties, everything works correctly.
What am I missing here?
If you are animating widgets, you need to make changes to the layout to have the results "stick". Just using the fillAfter stuff will give you some of the effects you see -- it is drawing them in the new location but they aren't really in the new location.
So, I would start by turning off any fill* settings (e.g., fillAfter) in your animation. See what your animation behaves like then. Most likely, it visually will now depict what the clicks tell you.
Then, set up an AnimationListener to get control when the animation ends, and at that point, make real changes to the widgets and their containers to affect your end positions.
Here is a sample project that demonstrates what I mean, albeit in an overly complicated fashion, since I am animating a custom View rather than an off-the-shelf widget.