Animation. How to remove flashing effect?

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

Animation. How to remove flashing effect?

Postby lyubomyr.dutko » Tue Sep 01, 2009 6:06 pm

Hi,

I am trying to resolve a task with animation flashing. I have already posted this issue on other forums, but still can't find any solution. So, problem is following.

I use two ImageViews to create animation of moving ball. The animation has following scenario:

    ball is moving from left to right (TranslateAnimation is started).
    ball stops (TranslateAnimation reached the end)
    in animation listener I set left ImageView's drawable to NULL and set right ImageView to display ball bitmap. Here I have flash effect.
    after this I run second animation which moves ball from right to left.

Could you please help with the animation issue? What I didn't take into account or what I missed here?
Thanks,
Lyubomyr
lyubomyr.dutko
Freshman
Freshman
 
Posts: 4
Joined: Tue Sep 01, 2009 6:00 pm
Location: Ukraine

Top

Postby mangaluve » Tue Sep 01, 2009 10:24 pm

First of all, you don't need two ImageViews to do that. Secondly, it's hard to say without seeing the code. It's probably that the View is drawn in it's original position after the animation ends. Please post your code if you want some help.
mangaluve
Experienced Developer
Experienced Developer
 
Posts: 82
Joined: Mon Mar 23, 2009 8:59 pm

Postby AsTeR » Tue Sep 01, 2009 10:55 pm

I got the same problem, but even if i'm only using one single view. Here is a copy paste of message I wrote for the android-developper mailing list, but i've never seen it again after my post :(

"Hello people,

I'm back to Android developpement with a great pleasure but i'm
experimenting a great problem...

Here is my code explained :

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. //This function move an element View to a new position described by xTargeted and yTargeted
  2.  
  3. private void animateMove(final View v, final int xTargeted, final int yTargeted){
  4.  
  5.  
  6.  
  7.                //here i'm getting the actual position of the view
  8.  
  9.                int x = ((AbsoluteLayout.LayoutParams)v.getLayoutParams()).x;
  10.  
  11.                int y = ((AbsoluteLayout.LayoutParams)v.getLayoutParams()).y;
  12.  
  13.  
  14.  
  15.                //creation of the animation
  16.  
  17.                TranslateAnimation t = new TranslateAnimation(0,xTargeted-x 0,yTargeted-y);
  18.  
  19.                t.setDuration(TaquoidConf.moveDuration);
  20.  
  21.                t.setInterpolator(new AccelerateInterpolator());
  22.  
  23.  
  24.  
  25.                //defining a listener
  26.  
  27.                t.setAnimationListener(new AnimationListener(){
  28.  
  29.  
  30.  
  31.                        public void onAnimationEnd(Animation animation) {
  32.  
  33.  
  34.  
  35.                               // !!!!!! Without this thread or just a call to its content the view goes to its ancient coordinates after animation
  36.  
  37.                                Thread th = new Thread(new Runnable(){
  38.  
  39.                                        public void run() {
  40.  
  41.                                                v.setLayoutParams(new AbsoluteLayout.LayoutParams(v.getLayoutParams().width, v.getLayoutParams().height, xTargeted, yTargeted));
  42.  
  43.                                        }
  44.  
  45.                                });
  46.  
  47.                                th.run();
  48.  
  49.                        }
  50.  
  51.  
  52.  
  53.                        public void onAnimationRepeat(Animation animation) {
  54.  
  55.  
  56.  
  57.                        }
  58.  
  59.  
  60.  
  61.                        public void onAnimationStart(Animation animation)
  62.  
  63.                        }
  64.  
  65.                });
  66.  
  67.  
  68.  
  69.                //Launching the animation on the view
  70.  
  71.                v.startAnimation(t);
  72.  
  73.        }
Parsed in 0.037 seconds, using GeSHi 1.0.8.4


If someone have already solved this problem I would enjoy to know the
answer.

Thanks"

Thanks for help !
Last edited by AsTeR on Wed Sep 02, 2009 9:22 am, edited 3 times in total.
AsTeR
Junior Developer
Junior Developer
 
Posts: 19
Joined: Tue Jun 17, 2008 8:36 am

Postby mangaluve » Wed Sep 02, 2009 8:58 am

please please use the code-tag to get your source formatted. You can mark the code and click the ".java" button to do that.
mangaluve
Experienced Developer
Experienced Developer
 
Posts: 82
Joined: Mon Mar 23, 2009 8:59 pm

Postby AsTeR » Wed Sep 02, 2009 9:16 am

Done,... but doesn't work :(
AsTeR
Junior Developer
Junior Developer
 
Posts: 19
Joined: Tue Jun 17, 2008 8:36 am

Postby mangaluve » Wed Sep 02, 2009 9:20 am

Click "edit" on you message. Mark all the code and click the ".java" button above. Also, unclick the "Disable BBCode in this post". Then it'll work.
mangaluve
Experienced Developer
Experienced Developer
 
Posts: 82
Joined: Mon Mar 23, 2009 8:59 pm

Top

Postby AsTeR » Wed Sep 02, 2009 9:23 am

You are nice with stupid guy ;)

Now that's nicer !
AsTeR
Junior Developer
Junior Developer
 
Posts: 19
Joined: Tue Jun 17, 2008 8:36 am

Postby lyubomyr.dutko » Wed Sep 02, 2009 9:55 am

Hi,

I can make my card stay at new position after animation finished. The only thing you have to do is to set fillAfter and fillEnabled attributes to TRUE.

But after this you will have to move graphics to next position (you should set ImageView new source) and again you will have flashing. In this case ImageView will show the new source anly if you do setAnimation(null), otherwise you will have old image displayed.

And by the way, after settings these attributes above, sometimes you will see that your canvas is not invalidating properly. After finishing animation the image (don't know why) stays at new position (not always).
Thanks,
Lyubomyr
lyubomyr.dutko
Freshman
Freshman
 
Posts: 4
Joined: Tue Sep 01, 2009 6:00 pm
Location: Ukraine

Postby AsTeR » Wed Sep 02, 2009 10:00 am

You can just move your view instead of creating a new one.

Look at what I've done in my thread.
AsTeR
Junior Developer
Junior Developer
 
Posts: 19
Joined: Tue Jun 17, 2008 8:36 am

Postby lyubomyr.dutko » Wed Sep 02, 2009 10:56 am

Hi,

and here comes my code.
Attachments
AnimationTest.zip
code describes the issue I have
(21.99 KiB) Downloaded 51 times
Thanks,
Lyubomyr
lyubomyr.dutko
Freshman
Freshman
 
Posts: 4
Joined: Tue Sep 01, 2009 6:00 pm
Location: Ukraine

Postby AsTeR » Wed Sep 02, 2009 6:57 pm

It seems that we've got the same problem, we are using the same kind of approach.
AsTeR
Junior Developer
Junior Developer
 
Posts: 19
Joined: Tue Jun 17, 2008 8:36 am

Postby mangaluve » Wed Sep 02, 2009 7:37 pm

I haven't analyzed it much, but one simple way to solve it would be to postpone the code in onAnimationEnd() by posting it in the UI thread. You could do this by introducing the following attribut
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. Handler mHandler = new Handler();
Parsed in 0.032 seconds, using GeSHi 1.0.8.4

and change the onAnimationEnd() to
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public void onAnimationEnd(Animation animation) {
  2.  
  3.         handler.post(new Runnable() {
  4.  
  5.                 public void run() {
  6.  
  7.                         // The old code from onAnimationEnd()
  8.  
  9.                 }
  10.  
  11.         });
  12.  
  13. }
Parsed in 0.034 seconds, using GeSHi 1.0.8.4

That'll remove the flickering. Basically, what happened in your case was that the animationListener is set on the last ImageView. Thus, the first one will be drawn correctly at the end of the animation. But before the second one can be drawn, the animationlistener is invoked and the images are swapped. Therefore the second one will have the same image as the first one (which has already been drawn and is not affected by the animationlistener). Thus, at one moment, both ImageViews will draw the same picture, thereby the flickering.
Last edited by mangaluve on Wed Sep 02, 2009 7:56 pm, edited 1 time in total.
mangaluve
Experienced Developer
Experienced Developer
 
Posts: 82
Joined: Mon Mar 23, 2009 8:59 pm

Postby AsTeR » Wed Sep 02, 2009 7:44 pm

I'll try.
AsTeR
Junior Developer
Junior Developer
 
Posts: 19
Joined: Tue Jun 17, 2008 8:36 am

Postby lyubomyr.dutko » Wed Sep 02, 2009 9:13 pm

it works :)

Thanks
lyubomyr.dutko
Freshman
Freshman
 
Posts: 4
Joined: Tue Sep 01, 2009 6:00 pm
Location: Ukraine

Postby AsTeR » Wed Sep 02, 2009 10:30 pm

Thank you, but for me it doesn't... I'm calling the handler instead of using my thread but it still flashing...

Another question more theorical : what does the 'm' in front of attributes name means ?
AsTeR
Junior Developer
Junior Developer
 
Posts: 19
Joined: Tue Jun 17, 2008 8:36 am

Top
Next

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: Majestic-12 [Bot] and 10 guests