I want to create a slideshow of images in which I want to repeat 5 images to come in a loop until a button is pressed. Also I want some effect in between the images so that the transition looks nice. I am able to create a slideshow, but the problem is that its not repeating.
here is my code:
public class Slides extends Activity implements OnClickListener {
Button button;
Boolean goingOn = false;
AnimationDrawable animation;
private TransitionDrawable trans;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.discolight);
final ImageView lights = (ImageView) findViewById(R.id.img);
button=(Button)findViewById(R.id.power);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(goingOn)
{
stopAnimation();
goingOn=false;
}
else
{
startAnimation();
goingOn=true;
}
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu m) {
MenuInflater inf = getMenuInflater();
inf.inflate(R.menu.frontscreenmenu, m);
return true;
}
class Starter implements Runnable {
public void run() {
animation.start();
}
}
private void startAnimation() {
animation = new AnimationDrawable();
animation.addFrame(getResources().getDrawable(R.drawable.a), 1000);
animation.addFrame(getResources().getDrawable(R.drawable.b), 1000);
animation.addFrame(getResources().getDrawable(R.drawable.c), 1000);
animation.addFrame(getResources().getDrawable(R.drawable.d), 1000);
animation.addFrame(getResources().getDrawable(R.drawable.e), 1000);
animation.addFrame(getResources().getDrawable(R.drawable.f), 1000);
animation.addFrame(getResources().getDrawable(R.drawable.g), 1000);
animation.addFrame(getResources().getDrawable(R.drawable.h), 1000);
animation.addFrame(getResources().getDrawable(R.drawable.i), 1000);
animation.addFrame(getResources().getDrawable(R.drawable.j), 1000);
animation.setOneShot(true);
ImageView imageView = (ImageView) findViewById(R.id.img);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
600, 800);
params.alignWithParent = true;
params.addRule(RelativeLayout.CENTER_IN_PARENT);
imageView.setLayoutParams(params);
imageView.setImageDrawable(animation);
imageView.post(new Starter());
}
private void stopAnimation() {
animation.stop();
}
Use The FrameAnimation for this
and add frameanimatin.setOneShot(false);
Related
In my project I have just one Activity that have View.
I think that it has two View that switch the View. The first View is my home that has one Button named "play" . when You click play Button in goes to the second View. Second View is my game.
And now my problem is that when I want to use onBackPressed() method in the second View, it closes the Activity. and onBackPressed() method do the same in both View.
How to handle onBackPressed() method in second View that return to the first View.
How to switch the View in onBackPressed()?
I am new with Android and now I really confused.
any suggestion? or any key word to search to solve my problem.
here is my code:
public class PTPlayer extends Cocos2dxActivity {
static Splash splash;
public static AppList appList;
static Noti_Queue noti_queue;
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Log.v("----------", "onActivityResult: request: " + requestCode + " result: " + resultCode);
if (requestCode == PTServicesBridge.RC_SIGN_IN) {
}
}
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
if (splash == null) {
splash = new Splash(this);
splash.set_identity("1");
}
if (appList == null) {
appList = new AppList(this);
appList.set_identity("1");
}
if (noti_queue == null) {
noti_queue = new Noti_Queue(this);
noti_queue.set_identity("1");
}
}
#Override
public void onNativeInit() {
initBridges();
}
private void initBridges() {
PTStoreBridge.initBridge(this);
PTServicesBridge.initBridge(this, getString(R.string.app_id));
if (PTJniHelper.isAdNetworkActive("kChartboost")) {
PTAdChartboostBridge.initBridge(this);
}
if (PTJniHelper.isAdNetworkActive("kRevMob")) {
PTAdRevMobBridge.initBridge(this);
}
if (PTJniHelper.isAdNetworkActive("kAdMob") || PTJniHelper.isAdNetworkActive("kFacebook")) {
PTAdAdMobBridge.initBridge(this);
}
if (PTJniHelper.isAdNetworkActive("kAppLovin")) {
PTAdAppLovinBridge.initBridge(this);
}
if (PTJniHelper.isAdNetworkActive("kLeadBolt")) {
PTAdLeadBoltBridge.initBridge(this);
}
if (PTJniHelper.isAdNetworkActive("kVungle")) {
PTAdVungleBridge.initBridge(this);
}
if (PTJniHelper.isAdNetworkActive("kPlayhaven")) {
PTAdUpsightBridge.initBridge(this);
}
if (PTJniHelper.isAdNetworkActive("kMoPub")) {
PTAdMoPubBridge.initBridge(this);
}
if (PTJniHelper.isAdNetworkActive("kFacebook")) {
PTAdFacebookBridge.initBridge(this);
}
if (PTJniHelper.isAdNetworkActive("kHeyzap")) {
PTAdHeyzapBridge.initBridge(this);
}
}
#Override
public Cocos2dxGLSurfaceView onCreateView() {
Cocos2dxGLSurfaceView glSurfaceView = new Cocos2dxGLSurfaceView(this);
glSurfaceView.setEGLConfigChooser(8, 8, 8, 0, 0, 0);
return glSurfaceView;
}
static {
System.loadLibrary("player");
}
#Override
protected void onResume() {
super.onResume();
if (PTJniHelper.isAdNetworkActive("kChartboost")) {
PTAdChartboostBridge.onResume(this);
}
}
#Override
protected void onStart() {
super.onStart();
if (PTJniHelper.isAdNetworkActive("kChartboost")) {
PTAdChartboostBridge.onStart(this);
}
}
#Override
protected void onStop() {
super.onStop();
if (PTJniHelper.isAdNetworkActive("kChartboost")) {
PTAdChartboostBridge.onStop(this);
}
}
#Override
protected void onDestroy() {
super.onDestroy();
}
#Override
public void onBackPressed() {
splash.Display();
splash = null;
super.onBackPressed();
}
}
here i think that in my second view:
public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelperListener {
// ===========================================================
// Constants
// ===========================================================
private static final String TAG = Cocos2dxActivity.class.getSimpleName();
// ===========================================================
// Fields
// ===========================================================
private Cocos2dxGLSurfaceView mGLSurfaceView;
private Cocos2dxHandler mHandler;
private static Context sContext = null;
public static Context getContext() {
return sContext;
}
// ===========================================================
// Constructors
// ===========================================================
#Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
sContext = this;
this.mHandler = new Cocos2dxHandler(this);
this.init();
Cocos2dxHelper.init(this, this);
}
// ===========================================================
// Getter & Setter
// ===========================================================
// ===========================================================
// Methods for/from SuperClass/Interfaces
// ===========================================================
#Override
protected void onResume() {
super.onResume();
Cocos2dxHelper.onResume();
this.mGLSurfaceView.onResume();
}
#Override
protected void onPause() {
super.onPause();
Cocos2dxHelper.onPause();
this.mGLSurfaceView.onPause();
}
#Override
public void showDialog(final String pTitle, final String pMessage) {
Message msg = new Message();
msg.what = Cocos2dxHandler.HANDLER_SHOW_DIALOG;
msg.obj = new Cocos2dxHandler.DialogMessage(pTitle, pMessage);
this.mHandler.sendMessage(msg);
}
#Override
public void showEditTextDialog(final String pTitle, final String pContent, final int pInputMode, final int pInputFlag, final int pReturnType, final int pMaxLength) {
Message msg = new Message();
msg.what = Cocos2dxHandler.HANDLER_SHOW_EDITBOX_DIALOG;
msg.obj = new Cocos2dxHandler.EditBoxMessage(pTitle, pContent, pInputMode, pInputFlag, pReturnType, pMaxLength);
this.mHandler.sendMessage(msg);
}
#Override
public void runOnGLThread(final Runnable pRunnable) {
this.mGLSurfaceView.queueEvent(pRunnable);
}
// ===========================================================
// Methods
// ===========================================================
public void init() {
// FrameLayout
ViewGroup.LayoutParams framelayout_params =
new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
ViewGroup.LayoutParams.FILL_PARENT);
FrameLayout framelayout = new FrameLayout(this);
framelayout.setLayoutParams(framelayout_params);
// Cocos2dxEditText layout
ViewGroup.LayoutParams edittext_layout_params =
new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
this.mGLSurfaceView = this.onCreateView();
// Switch to supported OpenGL (ARGB888) mode on emulator
if (isAndroidEmulator())
this.mGLSurfaceView.setEGLConfigChooser(8 , 8, 8, 8, 16, 0);
this.mGLSurfaceView.setCocos2dxRenderer(new Cocos2dxRenderer());
RelativeLayout relativeLayout = new RelativeLayout(getApplicationContext());
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);
params.addRule(RelativeLayout.ALIGN_PARENT_TOP);
relativeLayout.setLayoutParams(params);
//AdView adad = new AdView(this);
ClickBanner_CLickYab_Holder adad = new ClickBanner_CLickYab_Holder(this);
RelativeLayout.LayoutParams adad_params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
adad_params.addRule(RelativeLayout.CENTER_HORIZONTAL);
adad_params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
// adad.setToken(getString(R.string.adad_token));
adad.setLayoutParams(adad_params);
Button myButton = new Button(this);
myButton.setBackgroundResource(R.drawable.more);
RelativeLayout.LayoutParams adad_params1 = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
adad_params1.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
adad_params1.addRule(RelativeLayout.ALIGN_PARENT_TOP);
myButton.setLayoutParams(adad_params1);
myButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
PTPlayer.appList.Display();
}
});
Button myButton1 = new Button(this);
myButton1.setBackgroundResource(R.drawable.more);
RelativeLayout.LayoutParams adad_params2 = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
adad_params2.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
adad_params2.addRule(RelativeLayout.ALIGN_PARENT_TOP);
myButton1.setLayoutParams(adad_params2);
myButton1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
PTPlayer.appList.Display();
}
});
relativeLayout.addView(this.mGLSurfaceView);
relativeLayout.addView(adad);
relativeLayout.addView(myButton);
relativeLayout.addView(myButton1);
ClickBanner_CLickYab_Holder.setTestMode();
setContentView(relativeLayout);
}
public Cocos2dxGLSurfaceView onCreateView() {
return new Cocos2dxGLSurfaceView(this);
}
private final static boolean isAndroidEmulator() {
String model = Build.MODEL;
Log.d(TAG, "model=" + model);
String product = Build.PRODUCT;
Log.d(TAG, "product=" + product);
boolean isEmulator = false;
if (product != null) {
isEmulator = product.equals("sdk") || product.contains("_sdk") || product.contains("sdk_");
}
Log.d(TAG, "isEmulator=" + isEmulator);
return isEmulator;
}
}
you must use of Override Method for when back button pressed
if you want to stay on currnt activity use like this
#Override
public void onBackPressed() {
return;
}
if you want to use double click to exit and one click to stay you can use like this
first define a variable for double click
boolean doubleBackToExit = false;
and the Override backbutton method
#Override
public void onBackPressed() {
if (doubleBackToExit) {
//on double back button pressed
return;
}
this.doubleBackToExit = true;
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
doubleBackToExit=false;
}
}, 2000);
}
Then do this.
#Override
public void onBackPressed() {
super.onBackPressed();
Intent intent = new Intent(MainActivityPhase2.this, GlobalSearch.class);
startActivity(intent);
finish();
}
Just don't call the super.onBackPressed() everytime.
#Override
public void onBackPressed() {
if (isFirstView()) {
super.onBackPressed();
} else {
switchToFirstView();
}
Call in only when there isn't any last view available. Or where you want to close the App. The code will finish your activity when you are on the first activity. And switch to first activity if you are on second activity.
Just replace my methods as per your code.
Overriding onBackPressed() of the activity and provide your screen where you want to go.
onBackpressed() check which is the current view you are showing and according to move to the first view.
in your second class Cocos2dxActivity, place this code.
#Override
public void onBackPressed() {
this.finish();
}
If you have just one activity with two View you can use Fragments.
Using Fragments, Activity.OnBackPressed() will remove last fragment in the stack and you can resolve your problem.
So, in the activity you have to put a container in xml layout file:
<FrameLayout android:id="#+id/container" android:layout_width="match_parent"
android:clickable="true" android:layout_height="match_parent"/>
In the Activity java file:
getFragmentManager().beginTransaction()
.add(R.id.container,new YourHomeFragment())
.commit();
So to add second Fragment you can use this code:
getFragmentManager().beginTransaction()
.add(R.id.container,new YourPlayFragment())
.addToBackStack("YourPlayFragment") //string what you want
.commit();
Pay attention: you can call this code or in YourHomeFragment class (into button clickListener) or in your Activity (using a callback system). For example:
In YourHomeFragment -->
playButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
getFragmentManager().beginTransaction()
.add(R.id.container,new YourPlayFragment())
.addToBackStack("YourPlayFragment") //string what you want
.commit();
}
});
In this way, you have to declare two layout xml file for fragments and one for Activity.
List of java and relative xml files:
MainActivity.java
activity_main.xml
YourHomeFragment.java
fragment_your_home.xml <-- insert here your first View
YourPlayFragment.java
fragment_your_play.xml <-- play view
I need to trigger animation drawables after each other "Queue"
like when one of the animations finish the other start to work
now all animations is working good but all start in the same time but when I tried to put AnimationListener to make them trigger each other
I got error
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.hesham.salahshow/com.example.hesham.salahshow.MainActivity}: java.lang.RuntimeException: Unknown animation name: objectAnimator
any one can help ?
MainActivity
public class MainActivity extends ActionBarActivity {
private ImageView vectorImage;
private ImageView vectorImage2;
private ImageView vectorImage3;
private ImageView vectorImage4;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
vectorImage = (ImageView) findViewById(R.id.imageid);
vectorImage2 = (ImageView) findViewById(R.id.imageid2);
vectorImage3 = (ImageView) findViewById(R.id.imageid3);
vectorImage4 = (ImageView) findViewById(R.id.imageid4);
mAnim = AnimationUtils.loadAnimation(this, R.anim.path);
mAnim.setAnimationListener((Animation.AnimationListener) this);
vectorImage.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
vectorImage.startAnimation(mAnim);
((Animatable) vectorImage.getDrawable()).start();
// ((Animatable) vectorImage2.getDrawable()).start();
// ((Animatable) vectorImage3.getDrawable()).start();
// ((Animatable) vectorImage4.getDrawable()).start();
}});
}
}
Anim/path
<?xml version="1.0" encoding="utf-8"?>
<objectAnimator xmlns:android="http://schemas.android.com/apk/res/android"
android:propertyName="trimPathEnd"
android:valueFrom="0"
android:valueTo="1"
android:duration="1000"
android:valueType="floatType"
android:interpolator="#android:interpolator/linear">
</objectAnimator>
Thanks in advance :)
What is your minimum SDK version? ObjectAnimator was introduced in API 11.
Also, to put animations in sequence, you could override AnimationListener.onAnimationEnd() and use that to check which animation just ended and start the next one.
I have used another way which worked good for me
public class MainActivity extends ActionBarActivity {
private ImageView vectorImage;
private ImageView vectorImage2;
private ImageView vectorImage3;
private ImageView notiImageView;
private ImageButton next;
private int loopaya = 1;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
vectorImage = (ImageView) findViewById(R.id.imageid);
vectorImage2 = (ImageView) findViewById(R.id.imageid2);
vectorImage3 = (ImageView) findViewById(R.id.imageid3);
notiImageView = (ImageView) findViewById(R.id.notification);
next = (ImageButton) findViewById(R.id.next);
notiImageView.setVisibility(View.INVISIBLE);
vectorImage2.setVisibility(View.INVISIBLE);
vectorImage.setVisibility(View.INVISIBLE);
vectorImage3.setVisibility(View.INVISIBLE);
next.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
runThread();
}
});
}
private void runThread() {
final Handler h = new Handler();
final int delay = 1001; //milliseconds
h.postDelayed(new Runnable() {
#Override
public void run() {
runOnUiThread(new Runnable() {
#Override
public void run() {
if (loopaya == 1) {
vectorImage.setVisibility(View.VISIBLE);
((Animatable) vectorImage.getDrawable()).start();
loopaya++;
h.postDelayed(this, delay);
} else if (loopaya == 2) {
vectorImage2.setVisibility(View.VISIBLE);
((Animatable) vectorImage2.getDrawable()).start();
loopaya++;
h.postDelayed(this, delay);
} else if (loopaya == 3) {
vectorImage3.setVisibility(View.VISIBLE);
((Animatable) vectorImage3.getDrawable()).start();
loopaya++;
// h.postDelayed(this, delay);
notiImageView.setVisibility(View.VISIBLE);
Animation myFadeInAnimation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.fadein);
notiImageView.startAnimation(myFadeInAnimation);
}
}
});
h.postDelayed(this, delay);
}
}, delay);
}
I'm trying to make an app that draws a circle on a bitmap. Right now, I have a button that produces the circle. Instead, I would like to draw the circle where the user double-taps (instead of pressing a button). How can I do this programmatically? Here is the content of the activity so far:
public static final String KEY_PATH = "img.jpg";
private ZoomInZoomOut touch;
private Bitmap bitmap;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_image_display);
Intent intent = getIntent();
String path = getIntent().getStringExtra(ImageDisplayActivity.KEY_PATH);
try {
java.io.FileInputStream in = this.openFileInput(path);
bitmap = BitmapFactory.decodeStream(in);
bitmap = bitmap.copy(bitmap.getConfig(), true);
touch = (ZoomInZoomOut)findViewById(R.id.IMAGEID);
touch = arrangeImageView(touch);
touch.setImageBitmap(bitmap);
in.close();
Button draw = (Button) findViewById(R.id.draw);
draw.setOnClickListener(new View.OnClickListener(){
public void onClick(View v)
{
Bitmap bmOverlay = Bitmap.createBitmap(bitmap.getWidth(),
bitmap.getHeight(),
bitmap.getConfig());
Canvas canvas = new Canvas(bmOverlay);
Paint p = new Paint();
p.setAntiAlias(true);
p.setColor(Color.BLUE);
p.setStrokeWidth(2);
p.setStyle(Paint.Style.STROKE);
canvas.drawBitmap(bitmap,new Matrix(),null);
canvas.drawCircle(1000, 1000, 20, p);
touch.setImageBitmap(bmOverlay);
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
You have to implement GestureDetector and put your code in single/double click. Here you can replace button with bitmap.
TestActivity.java
iv.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
//putyour first activity call.
}
}
iv.setOnTouchListener(new OnTouchListener() {
GestureDetector gestureDetector = new GestureDetector(new MyGestureDetector(context));
#Override
public boolean onTouch(View v, MotionEvent event) {
return gestureDetector.onTouchEvent(event);
}
});
Now you have to create GestureDetector.java class.
public class MyGestureDetector extends SimpleOnGestureListener {
public Context context;
public String phno;
public MyGestureDetector(Context con)
{
this.context=con;
}
#Override
public boolean onDown(MotionEvent e) {
return super.onDown(e);
}
public MyGestureDetector(Context con) {
this.context=con;
}
#Override
public boolean onDoubleTap(MotionEvent e) {
System.out.println("in Double tap");
return true;
}
#Override
public boolean onSingleTapUp(MotionEvent e) {
System.out.println("in single tap up");
//put your second activity.
return super.onSingleTapUp(e);
}
}
In my android code my requirement is :--
when I click the button it will show an animation..this animation will run for 4 sec..then it will go to another activity.
my code is:--
public class Animation_test extends Activity {
private Handler handler;
Context context;
private TransparentProgressDialog pd;
Button btnOpenPopup;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.animation_test);
btnOpenPopup = (Button)findViewById(R.id.btn1);
buttonperform();
handler = new Handler();
pd = new TransparentProgressDialog(this, R.drawable.uktrafficlights);
}
public void buttonperform(){
btnOpenPopup.setOnClickListener(new Button.OnClickListener(){
#Override
public void onClick(View arg0) {
new Thread(new Task()).start();
}
});
}
class Task implements Runnable {
#Override
public void run() {
handler.post(new Runnable() {
#Override
public void run() {
pd.show();
}
Intent intent = new Intent(context, secondActivity.class);
startActivity(intent);
});
}
}
#Override
protected void onDestroy() {
//handler.removeCallbacks(new Ru);
if (pd.isShowing() ) {
pd.dismiss();
}
super.onDestroy();
}
private class TransparentProgressDialog extends Dialog {
private ImageView iv;
public TransparentProgressDialog(Context context, int resourceIdOfImage) {
super(context, R.style.TransparentProgressDialog);
WindowManager.LayoutParams wlmp = getWindow().getAttributes();
wlmp.gravity = Gravity.CENTER_HORIZONTAL;
getWindow().setAttributes(wlmp);
setTitle(null);
setCancelable(false);
setOnCancelListener(null);
LinearLayout layout = new LinearLayout(context);
layout.setOrientation(LinearLayout.VERTICAL);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
iv = new ImageView(context);
iv.setImageResource(resourceIdOfImage);
layout.addView(iv, params);
addContentView(layout, params);
}
#Override
public void show() {
super.show();
RotateAnimation anim = new RotateAnimation(0.0f, 360.0f , Animation.RELATIVE_TO_SELF, .5f, Animation.RELATIVE_TO_SELF, .5f);
anim.setInterpolator(new LinearInterpolator());
//anim.setRepeatCount(Animation.INFINITE);
anim.setDuration(4000);
iv.setAnimation(anim);
iv.startAnimation(anim);
}
}
}
But my code is only showing the animation..where is the problem???
No need of handler and thread for what you want to achieve. Animation has a Listener Animation.AnimationListener, with three callbacks.
onAnimationStart
onAnimationEnd
onAnimationRepeat
you can register the listener for your animation, and when onAnimationEnd is called you can start your activity. E.g
anim.setAnimationListener(new Animation.AnimationListener() {
#Override
public void onAnimationStart(Animation animation) {
}
#Override
public void onAnimationEnd(Animation animation) {
Intent intent = new Intent(Animation_test.this, secondActivity.class);
startActivity(intent);
}
#Override
public void onAnimationRepeat(Animation animation) {
}
});
I'm doing a property animation of different imagebuttons. my code perfectly works for a single imagebutton, but whenever i add some more buttons or images, everything starts animating.
here is my code
public class MainActivity extends Activity {
// ImageButton jackfruit = (ImageButton) findViewById(R.id.btnjackfruit);
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button but = (Button) findViewById(R.id.btn);
but.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
ball();
}
private void ball() {
ImageButton ball = (ImageButton) findViewById(R.id.btnball);
ball.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(final View v) {
//ImageButton b = (ImageButton) findViewById(R.id.btnball);
ImageView banan = (ImageView) findViewById(R.id.banana);
banan.setVisibility(View.VISIBLE);
} // onClick
});ObjectAnimator horizontalAnimator = ObjectAnimator.ofInt(new ImageButtonAnimatorHelper(ball), "marginLeft", 0, 600);
horizontalAnimator.setDuration(2000);
horizontalAnimator.setRepeatCount(ValueAnimator.INFINITE);
horizontalAnimator.setRepeatMode(ValueAnimator.REVERSE);
horizontalAnimator.setInterpolator(new LinearInterpolator());
horizontalAnimator.start();
} class ImageButtonAnimatorHelper {ImageButton ballButton;
private ImageButtonAnimatorHelper(ImageButton imagebutton) {ballButton = imagebutton; }
public void setMarginLeft(int margin) {
ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) ballButton.getLayoutParams();
params.leftMargin = margin;
ballButton.setLayoutParams(params);
} // setMarginLeft
}} // ImageButtonAnimatorHelper
);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}}
Can anyone tell why each of my object is moving?