I was creating animation between 2 Scenes using TransitionManager.go(Scene,Transition) and everything worked just fine but after the animation finished I was no longer capable of clicking on the button which was moved from the center of the screen to the left side.
Looking around the Internet I found that this animation actually doesn't even move the Views, just animates them so I have to update their positions to new ones.
Isn't there any better way to do this than manually .setLayoutParams for all the Views in the Scene?
I realized that my Views actually were in the right positions after the animation but I had to reset my OnClickListeners every time Scenes changed
Transition.TransitionListener listener = new Transition.TransitionListener() {
#Override
public void onTransitionEnd(Transition transition) {
//get view references from the new Scene and
//reassign on click listeners to them
}
}
I just assigned this listener to my Transition and everything worked fine.
Here is the post that helped me see my mistake.
Related
I would like to show a custom animation to match the other animations that I have in my RecyclerView. I can’t find a straight forward way of adding custom animations for removal. I know that when RecyclerView replaced ListView one of the talking points was the ability to know when items are added or removed rather than simply saying the dataset has changed and updating everything, so I figured there would be an easy way to add an animation to a View when it is removed that I am missing.
When I add an animation to a view that is removed the animation will not play. This is likely because the View is removed and the animation stops. Is there an easy way to add an animation to a View that doesn’t get cut off? I'm assuming that I could use a second thread, but I want to know if I am missing something.
//code for removal
holder.button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
//animation to be added here on view
list.remove(holder.getAdapterPosition());
notifyItemRemoved(position);
notifyItemRangeChanged(position,list.size()-position);
}
});
All add/change/delete/move animations in recyclerView are made by ItemAnimator (by default animator is DefaultItemAnimator). So if you need custom delete animation you should provide custom ItemAnimator via recyclerView.setItemAnimator(animator) method.
I suggest to extend from SimpleItemAnimator and override animateRemove method.
I have xxx of type ImageView. If I click it, the event handler animate will be triggered to animate it.
public void animate(View view) {
ImageView xxx= findViewById(R.id.xxx);
xxx.animate().rotation(7200f).setDuration(3000);
}
It works only for the first click but for the subsequent clicks the animation does not work.
Question
How to fix this issue?
Keep in mind that rotation sets the rotation value to the provided float.
You are probably looking for rotationBy if you want to always rotate by that value
inception sounds
It might not be the best idea, but here's a 4 second gif of what I'm trying to do and the problem I've run into.
https://i.imgur.com/Z3iAyNc.gifv (sorry, embedding wasn't allowed).
I have a RecyclerView with in each item a LinearLayout with category details and a hidden LinearLayout with another recyclerView. The idea is you see the categories, and once you tap on it, it expands to show the relevant posts. Another tap on the category should open the category detail page and a tap on a post should open the relevant post detail page.
I have it working, but as you can see in the gif, I have to tap at least two times, even though I never wrote it like that. It's the same for the LinearLayout's onClickListener It's like the parent RecyclerView hijacks the first tap.
Here's a schematic rundown of my code
adapter.setOnItemTouchListener(new RecyclerItemListener.RecyclerTouchListener() {
#Override
public void onClickItem(View v, int position) {
final LinearLayout postView = (LinearLayout) v.findViewById(R.id.profileCheckinDetailsView);
// The IF statement prevents reloading the view when it is already open.
if (postView.getVisibility()==View.GONE){
RelativeLayout itemView = (RelativeLayout) v.findViewById(R.id.ItemView);
itemView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
[... etc]
And beneath it there's another setOnItemTouchListener for the child RecyclerView.
Am I doing this right, and if so, how to make sure both items register the first tap as well?
Thanks in advance!
Sometimes typing out a question helps you think differently. I removed the top recyclerview's touch listener and replaced the item layout with this. Both layouts get their own onClickListener. With ((LinearLayout)v.getParent()) I managed to have them control eachother.
Much easier and more effective I believe.
I have a listView that has a layout animation that fades in each item one at a time.
lac = new LayoutAnimationController(AnimationUtils.loadAnimation(this, R.anim.listview_2), 0.25f);
listOptions.setLayoutAnimation(lac);
listOptions.setLayoutAnimationListener(new Animation.AnimationListener() {
#Override
public void onAnimationStart(Animation animation) {
}
#Override
public void onAnimationEnd(Animation animation) {
}
#Override
public void onAnimationRepeat(Animation animation) {
}
});
When the user selects an item, the listView displays a new set of items - each fading in one at a time. However, if the fade in animation of the items has not completed when the user selects an item and causes a new set to fade in, then these animations overlap causing and the previous items can be seen while the new ones are fading in. It looks like a blinking glitch on the ListView.
onItemClick(), even if I call listView.getLayoutAnimation.getAnimation().cancel(); I still get the same blinking problem.
I have also tried listView.clearAnimation();, still didn't work.
I have also tried: listView.setLayoutAnimation(null); and resetting. Still didn't work.
It appears I am unable to stop or cancel the animation!
All I want to do is, onItemclick() in my listView, to stop the animation or empty / clear the listView then reload the new items into the listView and fade them in using the animation, with no overlap - and therefore - no blinking glitch.
I do not want to disable the listView until the animation completes, then re-enable, because it can create awkwardly long wait times.
Animation in ListViews are challenging which is one of the reasons Google released RecyclerView. However, this video may have some clues for how to make this work for you: https://www.youtube.com/watch?v=8MIfSxgsHIs
I can't provide the code for the moment I'll update the question in the nearest future, but I'll explain the situation and you can tell me what to check first of all.
I have a Gallery with a set of ImageViews.
When ImageView is selected, view.startAnimation(grow); is cast. Everything works perfect.
Then I tap (onTouchEvent starts another animation on the unselected view: view.startAnimation(decrease);)
Everything works fine on the first element.
But when I choose the next imageview, grow animation works fine aswell, but decrease animation works on both of the imageViews. So it seems that startAnimation method runs the animation on all the imageViews that were choosen previously.
I had no luck finding the same question on stackoverflow. Will be very appreciate if you give me some ideas.
It may help someone.
Finally I've found the solution.
I have 2 methods:
animationShow(View view) {
View.startAnimation(animationShow);
}
and
animationHide(View view) {
View.startAnimation(animationHide);
}
I also have 2 views to work with: currently selected view (selectedView) and previously selected view (prevView), so I hide animation on prevView and show it on selectedView.
To avoid gallery issue with hiding animation, I changed animationShow() method:
animationShow(View view) {
View.startAnimation(animationShow);
if (prevView != null) {
prevView.cancelAnimation();
}
}
When new item is selected (and old item was hidden) I just cancel all the animations on the prevView. It helped me. Hope it will help someone else.