How to show Images after animation end in android? - android

In my android application I have four imageviews when I click any one of that all(4) images are animating. I set the zoomout animation for all the images. once the animation is finished I am starting a new activity. The problem is once i click a back button The images(all the 4) images are hide. If I start a application from home screen the Images are showing. please anyone help me how to show the images once i click the back button
synopsis.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
//synopsis.setBackgroundResource(R.drawable.aa);
synopsis.startAnimation(animZoomOut);
team.startAnimation(animZoomOut);
music.startAnimation(animZoomOut);
gallery.startAnimation(animZoomOut);
//synopsis.startAnimation(android.R.anim.slide_in_left);
animZoomOut.setAnimationListener(new 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
intent = new Intent(HomeActivity.this, Activity_Synopisis.class);
startActivity(intent);
}
});
}
});
<?xml version="1.0" encoding="utf-8"?>
<scale
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="2000"
android:fromXScale="1.0"
android:fromYScale="1.0"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="0"
android:toYScale="0" >
</scale>

The activity is being recreated thus the animation result is gone, you either need to have some sort of preference or pass a variable in the bundle, when the activity after the animation loads, set the variable 'animation_finished' to true and then simply check in the oncreate of the imageview activity: if true: show/hide your images appropriately

When the new activity is started, the old activity with the 4 images will remain in the state (i.e. with all images zoomed-out), so when you resume the old activity, you won't see that. One solution is to set the state of the 4 images to "normal" (i.e. show them) in the onResume() method of your old activity.

As per your short note and my understanding,
intent = new Intent(HomeActivity.this, Activity_Synopisis.class);
startActivity(intent);
synopsis.cancel();
team.cancel();
music.cancel();
gallery.cancel();
Try this one,It may help you out...

Thanks for the answer all.
I resolved this with the follo
synopsis.clearAnimation();
team.clearAnimation();
gallery.clearAnimation();
music.clearAnimation();
Added these above lines of code in Resume

Related

How to set return imagebutton's Alpha to the default when I back to the previous page

My homepage has a imagebutton. When I click the imagebutton, imagebutton's Alpha will change to 150. But when I back to the previous page, the imagebutton will still show Alpha(150) Instead of the default Alpha. How can I do when I back the previous page, the imagebutton will show the default ?
** I change my imagebutton's Transparency in java
like this :
btn_route.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
btn_route.getBackground().setAlpha(150);
Intent change_stationArea = new Intent();
change_stationArea.setClass(MainActivity.this,
stationArea.class);
startActivity(change_stationArea);
}
});
Add this to your activity/fragment and it should do the trick
#Override
protected void onResume()
{
super.onResume();
btn_route.getBackground().setAlpha(255);
}

changing images through ling click in android

i am making a flashlight app in which i am using using two images, one each for flashoff state and flashon state respectively.
i want to have animation such that these two images get toggled(image 1 apperas then image2 then again image 2..infinite times) when there is longclick..
that is iwant to show this in longclicklistner...
here is what i have done..
i am using this animation..
<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android="http://schemas.android.com/apk/res/android">
<alpha android:duration="1000" android:repeatCount="infinite" android:repeatMode="reverse" android:fromAlpha="0.3" android:toAlpha="1.0" />
and
#Override
public boolean onLongClick(View arg0) {
// TODO Auto-generated method stub
tButton.startAnimation(flickon); //tbutton is an image button
return true;
}
});
}
using this animation is happening but images are not switching..please help
ImageView image = (ImageView) findViewById(R.id.test_image);
image.setImageResource(R.drawable.xxx);
use the above code to set an image to the image view and use a thread that can change contents in the UI bascially some thing like this
public void onLongClick(View v) {
new Thread(new Runnable() {
public void run() {
ImageView image = (ImageView) findViewById(R.id.test_image);
image.setImageResource(R.drawable.xxx);
}
}).start();
}
You can loop over it for as many times as you want.

Implementing slide transition after a option item selected android

I build a action bar.Which contain a item say setting (image).After clicking on the image the another activity is being started.
But I want the starting activity to show sliding transition effect.current activity slide left and hide and starting activity should slide from right to left.
here is code
code for selecting the item
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()){
case R.id.setting:
goToSetting();
}
return super.onOptionsItemSelected(item);
}
gotoSetting function :
public void goToSetting() {
// Do something in response to button
Intent intent = new Intent(this, DisplayMessageSetting.class);
startActivity(intent);
}
which is calling activity named "DisplayMessageSetting"
please help
Edit the onCreate method in your DisplayMessageSetting activity like this :
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//specify the animation
overridePendingTransition(R.anim.slide_left_in, 0);
//...
}
Create a slide_left_in.xml file in your res/anim folder (create the folder if it doesn't exist) and paste the following :
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromXDelta="100%p" android:toXDelta="0" android:duration="400"/>
</set>
This way you just specified an animation set with one translate animation in it.
You have a lot more options to tweak that animation, you can learn a bit more about that here.

How to animate individual views on Activity transition?

How can I trigger animations on individual views when switching activities?
I.e. if the user clicks a button to go to the next page, I'd like some of my views to fly off screen, and have the background crossfade into the next screen, instead of having the whole screen be animated as one piece.
Is this possible? And if so, how should it be done? (I'm using the most recent API, 4.1, and it doesn't have to be backwards compatible)
EDIT: Currently, doing the transition-in animation is working fine by calling it in onResume(), but when I press back, the activity switches faster than any animations started in onPause() so that makes me think there's a better way/place to do this.
Overriding onResume() works fine, but onPause/onStop don't wait for
the animation to complete before moving to the next screen.
What ever starts the event ex. button click would need to start the animations before start activity is called.
button.setOnClickListener(new ViewOnClickListener() {
#Override
void onClick(... {
// start animations
// wait till they are finished
// start activity
}
});
Since every event that starts a new activity is going to have animation code I would also recommend moving it into some sort of helper class to avoid having duplicate code all over the place. ex.
button1.setOnClickListener(new ViewOnClickListener() {
#Override
void onClick(... {
helper.AnimateViews(/* probably pass activity or context */);
// start activity
}
});
button2.setOnClickListener(new ViewOnClickListener() {
#Override
void onClick(... {
helper.animateViews(/* probably pass activity or context */);
// start activity
}
});
public class ViewAnimiationHelper {
public void animateViews(Activity activity) {
// find all views if not found then don't animate them
View view1 = activity.findViewById(R.id.view1);
if(view1 != null) {
// animate view
}
View view2 = activity.findViewById(R.id.view1);
if(view2 != null) {
// animate view
}
}
}
This is all sudo java code but hopefully enough for you to get the idea. Good luck!
You can set up animations (like slide) when you switch between activities like this :
In the res folder, create an anim folder
For example, put two xml files for slide.
slide_in.xml
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate android:fromXDelta="100%" android:toXDelta="0%"
android:fromYDelta="0%" android:toYDelta="0%"
android:duration="200"/>
</set>
slie_out.xml
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate
android:fromXDelta="100%" android:toXDelta="0%"
android:fromYDelta="0%" android:toYDelta="0%"
android:duration="200" />
</set>
Then on your java code just write this :
Intent i = new Intent(YourActivity.this, OtherActivity.class);
this.startActivity(i);
overridePendingTransition(R.anim.slide_in, R.anim.slide_out);
If you are testing that on a real device, don't forget to allow it to play animations (Settings -> Display -> Animations -> All Animation)
Hope it helps !:)

Animation is not working in Emulater

i am enable to load animation in Emulater..Its working fine with any real device..
public class MainActivity extends Activity {
private ImageView imgView;
private Animation animation;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
animation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.grow);
animation.setRepeatCount(50); // Repeat animation infinitely
animation.setRepeatMode(Animation.REVERSE);
imgView = (ImageView) findViewById(R.id.imgView);
imgView.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
imgView.startAnimation(animation);
new Handler().postDelayed(new Runnable() {
public void run() {
Intent it = new Intent(getApplicationContext(), MyWebView.class);
startActivity(it);
}
}, 5000);
}
});
}
and my anim xml file is following
<rotate
xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="0"
android:toDegrees="360"
android:pivotX="50%"
android:pivotY="50%"
android:duration="50" />
I think you Might have Disabled Animations in Emulator:
Check that:
Settings>Display>Animation..
Hope that helps your Problem
For anyone running into similar issues when using ObjectAnimator, in my case I had to enable the developer settings on the emulator and then go into "Settings" > "Developer options" > "Drawing" section
In this "Drawing" section you'll find different options for each animation type, in my case the "Animator duration scale" was off, after setting it to "1x" I started seeing the animations on the emulator.

Categories

Resources