Saturday, March 8, 2014

A small problem on TranslateAnimation animation


 
package com.example.testpic;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;
import android.widget.Button;
import android.widget.ImageView;

public class MainActivity extends Activity {
ImageView image;
Button start;
Button cancel;

@ Override
public void onCreate (Bundle savedInstanceState) {
super.onCreate (savedInstanceState);
setContentView (R.layout.activity_main);

image = (ImageView) findViewById (R.id.main_img);
start = (Button) findViewById (R.id.main_start);
cancel = (Button) findViewById (R.id.main_cancel);

/ ** Set the animation shift rightward shift 150 * /
final TranslateAnimation animation = new TranslateAnimation (0, 150, 0,
0);
animation.setDuration (2000) ;/ / set the duration of the animation
animation.setRepeatCount (2) ;/ / set the number of repetitions
animation.setRepeatMode (Animation.REVERSE) ;/ / set in the opposite direction to perform

start.setOnClickListener (new OnClickListener () {
public void onClick (View arg0) {
/ ** Start the animation * /
image.setAnimation (animation);
animation.startNow ();
}
});

cancel.setOnClickListener (new OnClickListener () {
public void onClick (View v) {
/ ** End of the animation * /
animation.cancel ();
}
});
}

@ Override
public boolean onCreateOptionsMenu (Menu menu) {
getMenuInflater () inflate (R.menu.activity_main, menu);.
return true;
}
}


Layout file:
 

android: layout_width = "fill_parent"
android: layout_height = "fill_parent"
android: orientation = "vertical">

android: id = "@ + id / main_img"
android: layout_width = "wrap_content"
android: layout_height = "wrap_content"
android: background = "@ drawable / center_qq"
android: layout_gravity = "center"
/>


Click on the button when I want to put a simple animation, but clicking did not respond, if I move out of the movie, not on the onclick event of the button which is normal, I do not know why the<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
The setAnimation replaced startAnimation
Reply:
cited a floor guoyoulei520 reply:
the setAnimation replaced startAnimation

Well, you can, but why, animate animation can not open it? Why, then, can be used on the outside onclick set, and put inside it must start onclick
Reply:
reference to the second floor luqing414 reply:
Quote: references to a floor guoyoulei520 reply:

The setAnimation replaced startAnimation

Well, you can, but why, animate animation can not open it? Why, then, can be used on the outside onclick set, and put it inside onclick must start

Start is enabled threads, each activty is loaded asynchronously, with the Strat is loaded and activity together, and you have to click after the start, that is set up,,,
Reply:
reference to the third floor heaimnmn reply:
Quote: references to the second floor luqing414 reply:

Quote: references to a floor guoyoulei520 reply:

The setAnimation replaced startAnimation

Well, you can, but why, animate animation can not open it? Why, then, can be used on the outside onclick set, and put it inside onclick must start

Start is enabled threads, each activty is loaded asynchronously, with the Strat is loaded and activity together, and you have to click after the start, that is set up,,,

You are not backwards
Reply:
activity is the main thread is automatically turned on, the child thread needs to start

No comments:

Post a Comment