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.
Related
i have implemented an animation on one of my image views. My problem is that the animation will NOT stop at all. I call everything clearanimation i set it to null set it to cancel and it still wont stop.
public void tiltani(){
ImageView vault = (ImageView)findViewById(R.id.vault2) ;
Animation tilt = AnimationUtils.loadAnimation(this, R.anim.tilt);
vault.startAnimation(tilt);
}
public void stopani() {
Animation tilt = AnimationUtils.loadAnimation(this, R.anim.tilt);
vault.clearAnimation();
vault.setAnimation(null);
tilt.cancel();
tilt.reset();
}
here is xml file
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<rotate
android:fromDegrees="0"
android:toDegrees="6"
android:pivotX="50%"
android:pivotY="50%"
android:duration="500"
android:repeatCount="infinite"/>
<rotate
android:fromDegrees="6"
android:toDegrees="-2"
android:pivotX="50%"
android:pivotY="50%"
android:duration="500"
android:repeatMode="reverse"
android:repeatCount="infinite"
/>
here is where i start it
Intent intent1 = getIntent();
if (intent1.hasExtra("id1")) {
tiltani();
and i try to stop/cancel everything in an onclick method
vault.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
vault.setImageDrawable(ContextCompat.getDrawable(MainActivity.this, R.drawable.chestopen));
stopani();
update
Animation tilt = AnimationUtils.loadAnimation(this, R.anim.tilt);
if (intent1.hasExtra("id1")) {
vault.startAnimation(tilt);
vault.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
vault.setImageDrawable(ContextCompat.getDrawable(MainActivity.this,
R.drawable.chestopen));
vault.setAnimation(null);
You can just use vault.startAnimation(tilt); to start your animation, and use vault.setAnimation(null); to stop your animation.
You have initialized Animation a second time in stopani() method. Your view initialization and animation initialization should be global.
Your code should be like this.
ImageView vault = (ImageView)findViewById(R.id.vault2); //Global variable
Animation tilt = AnimationUtils.loadAnimation(this, R.anim.tilt); //Global variable
public void tiltani(){
vault.startAnimation(tilt);
}
public void stopani() {
vault.clearAnimation();
vault.setAnimation(null);
tilt.cancel();
tilt.reset();
}
Hope, It will help you.. :)
I am working on android. I want to create a rotating image and select parts on it. For example if the image is a human head then while its rotating, the ears can be selected. Now I did the image part selection, but I don't know how to rotate it? Can somebody show me an easy way?
You have 2 ways to rotate a image, i put the simple with xml.
First inside directory res create a directory with the name anim
inside the directory anim create a file xml with this code:
<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="0"
android:toDegrees="360"
android:pivotX="50%"
android:pivotY="50%"
android:duration="1000"
>
</rotate>
this code is the instruction to make a image rotate.
finally your main activity must look like that:
public class MainActivity extends Activity implements OnClickListener{
ImageView imagen; //declare the image will use
Button boton; // this button will activie de rotation
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imagen = (ImageView) findViewById(R.id.iv);
boton = (Button)findViewById(R.id.bt);
boton.setOnClickListener(this);
}
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.bt:
Animation rotacion; // declare an animation
rotacion = AnimationUtils.loadAnimation(this,R.anim.rotar);
rotacion.reset();
imagen.startAnimation(rotacion);
break;
default:
break;
}
}
You should use http://developer.android.com/reference/android/view/animation/RotateAnimation.html class to make animation and animate your view
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
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.
How can I spin a image wheel in an activity on android with the help of touch event? I need some guideline or link of any tutorial.
This is typically done with a couple pieces. This is how I do it in one of my apps. *Note: This is not a smooth wheel, so much as it starts and stops at the top (which was intentional). You can lookup more about Animation on the dev site.
Main XML that has an image:
<ImageView
android:id="#+id/anim_example"
android:src="#drawable/loading_circle"
android:layout_width="30sp"
android:layout_height="30sp"
android:onClick="RunAnimation" />
Here are the parts in code that run the animation
public void RunAnimation(View v)
{
//The onClick method has to be present and must take the above parameter.
StartLoading();
//This will delay the stop for 5 seconds
//Normally you would want to actually have this run based on some other input/data.
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
StopLoading();
}
}, 5000);
}
public void StartLoading() {
ImageView refreshImage = (ImageView) this.findViewById(R.id.anim_example);
refreshImage.setImageDrawable(getResources().getDrawable(R.drawable.loading_circle));
Animation rotateLoading = AnimationUtils.loadAnimation(this, R.anim.rotate);
refreshImage.clearAnimation();
refreshImage.setAnimation(rotateLoading);
}
public void StopLoading() {
ImageView refreshImage = (ImageView) this.findViewById(R.id.anim_example);
if (refreshImage.getAnimation() != null)
{
refreshImage.clearAnimation();
refreshImage.setImageDrawable(getResources().getDrawable(R.drawable.loading_circle));
}
}
anim.rotate:
<?xml version="1.0" encoding="utf-8"?>
<rotate
xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="0"
android:toDegrees="359"
android:duration="2000"
android:repeatMode="restart"
android:repeatCount="-1"
android:pivotX="50%"
android:pivotY="50%">
</rotate>