I'm working with gallery widget.
I've attached layout animation that fades in element in gallery.
It works well.
But when I change content of gallery, and refresh adapter with notifyDataSetChanged();
New elements show up, but there is no layout animation for them.
How to implement that effect?
I frequently update gallery content, and I need that effect every time.
Here is a code:
<com.rtrk.gui.mainmenu.gallery.A4TVGallery
android:id="#+id/mainMenuGallery"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:layoutAnimation="#anim/a4tv_gallery_controller"
android:persistentDrawingCache="animation" />
// Notify new data
mainMenuAdapter.notifyDataSetChanged();
// Set default selection
mainMenuGallery.setSelection(defaultSelectedIndex);
TNX!
Layout animation as it is described in documentation "Defines the layout animation to use the first time the ViewGroup is laid out." So this is used only the first time you show your view.
I have recently done something similar, and I don't know if it is the best solution, but you can start the animation in the adapter when the system calls the getView method. The important thing there is not to create an animation object in the getView method but rather in adapter constructor just once and then reuse the same animation for the views you would like to show with the desired animation.
If you would like to show the animation only on the new views than create a flag that will signal whether the view has been shown for the first time and use the view IDs to associate the view with the correct flag.
Use the setAnimation method on the view rather then startAnimation if you want to control when the animation will be fired. It is useful if you want to create an effect where the views are gradually appearing on the screen.
Related
I use viewPager.setCurrentItem(position) for opening a specific imageView item from my ViewPager.
This method works and It shows me the necessary imageView according to its position, but before I notice the image view on my screen I have to look at pretty fast slide which I want to hide.
How can I do this?
One of the solutions I made up in my mind was to use timer to load a view pager on the background while being invisible to the user. Though 0.3 seconds is quite fast I want to find a more elegant way if it exists!
Add extra argument to the method to set the smoothScroll as false.
viewPager.setCurrentItem(position, false)
I have a card-like view with elevation and a white background that I want to expand to fill up the whole screen. It's a card in a list (my own custom layout, not a CardView), and I want to make it take up the whole screen when it's tapped via a Fragment transition.
My first idea is to create a fake, identical view in the new fragment, place it at the item's position, and animate it to the top, while animating its layout bounds to take up the whole screen. However, I don't think this is the best idea, as Android will have to remeasure the layout every single frame while the animation is running (likely to lag). Is there a way I can get this effect in a clean way? I'm going to be using fragment transitions, so hopefully I can use Animator in some way, but I'll take any solution.
You can try to do the same, but instead of relayouting, do redrawing. Create custom implementation of view's onDraw(), it's not that hard.
View will fill entire screen but at the start of animation will draw only initial part.
Or you can just try your approach, it's easy to implement and may be it is not that slow.
Also, may be directly modifying view's setLeft(), setRight(), etc. with Animators is a valid solution.
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 :)
Is it possible to animate part of an activity launch?
I am not wanting my action bar to animate, however the rest of the view should slide in.
I have tried using a Gallery for this, however I have not been able to animate the gallery while programatically setting the selected view. This is because the gallery does not load more than the currently displayed view and its immediate adjacent views.
When you can use the viewflipper for this. Which shows 1 child at a time. You can set a IN and OUT animation for the views. So when you set the activew view index animations will be applied.
Trying to do the following:
animTimeChange = AnimationUtils.loadAnimation(this, android.R.anim.slide_in_left);
itemTime.startAnimation(animTimeChange);
itemTime.setText("new text");
but the animation happens thru blank screen (i.e. original text is cleared, then new text appears with animation). How to avoid that blank screen?
(my TextView is part of ListView row, I've tried to use TextSwitcher - it doesn't work properly; for ViewFlipper - I am not sure where add Views there, since this is part of the ListView)
TextSwitcher is exactly what you should be using for this. Check out the API Demo for TextSwitcher.
The way you should implement this is in your ListAdapter, provide TextSwitcher views to the ListView instead of TextViews. Then you can just call TextSwitcher.setText() on the list item you want to change.
Note that you should imediately get rid of your reference to the list item to avoid REALLY messing up listview.