Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid Animation Doesn't Work on first run
    primarykey
    data
    text
    <p>So this is the issue.<br/> Animation at first run doesn't work, I have no idea why.<br/> At first I used an xml for animation, but in that way animation worked only on first try and never again, so I changed and make everything in java code..<br/> But now, well it always runs except on first try.<br/><br/> Have to clear up that I have to work on a 2.2 (froyo) version.</p> <pre><code>public class HomePage extends Activity { protected View menu; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_home_page_portrait); ImageButton plus = (ImageButton) findViewById(R.id.button1); menu = (View) findViewById(R.id.layoutmenu); plus.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //menu.clearAnimation(); Animation animation = new TranslateAnimation(0,-menu.getWidth(),0,0); menu.clearAnimation(); if(menu.isShown()) { animation.setDuration(500); animation.setFillAfter(true); menu.setAnimation(animation); menu.setVisibility(View.GONE); } else { animation.reset(); animation = new TranslateAnimation(-menu.getWidth(),0,0,0); animation.setDuration(500); animation.setFillAfter(true); menu.setVisibility(View.VISIBLE); menu.setAnimation(animation); } } }); } } </code></pre> <p>Any clues?</p> <p><strong>EDIT</strong><br/> So I've changed my code but now doesn't work at all.<br/><br/></p> <pre><code> public void onClick(View v) { //menu.clearAnimation(); Animation animation; menu.clearAnimation(); if(menu.isShown()) { //animation.reset(); animation = new TranslateAnimation(0,-menu.getWidth(),0,0); animation.setDuration(500); animation.setFillAfter(true); animation.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { // TODO Auto-generated method stub } @Override public void onAnimationRepeat(Animation animation) { // TODO Auto-generated method stub } @Override public void onAnimationEnd(Animation animation) { // TODO Auto-generated method stub menu.setVisibility(View.GONE); } }); menu.setAnimation(animation); menu.setVisibility(View.GONE); } else { //animation.reset(); animation = new TranslateAnimation(-menu.getWidth(),0,0,0); animation.setDuration(500); animation.setFillAfter(true); animation.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { // TODO Auto-generated method stub menu.setVisibility(View.VISIBLE); } @Override public void onAnimationRepeat(Animation animation) { // TODO Auto-generated method stub } @Override public void onAnimationEnd(Animation animation) { // TODO Auto-generated method stub menu.setVisibility(View.VISIBLE); } }); menu.setAnimation(animation); //menu.setVisibility(View.VISIBLE); } animation.reset(); } }); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload