Automatic image zoom without touching the screen - android

I want to zoom an image automatically without touching the screen.
I.e. the image must be zoomed in as soon as the activity starts without any touch from the user.

Inside onCreate of MainActivity class you should define AnimationUtils and load the Animation on image view to whom you want to zoom Automatically.
Now make an xml class inside the anim and declare the xml inside load animation as second parameter.
this is the Java Class
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ImageView image = (ImageView)findViewById(R.id.imageView);
Animation animation1 = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.zoom);
image.startAnimation(animation1);
}
}
This is the Anim xlm for zoom animation
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXScale="0.5"
android:toXScale="3.0"
android:fromYScale="0.5"
android:toYScale="3.0"
android:duration="5000"
android:pivotX="50%"
android:pivotY="50%" >
</scale>
<scale xmlns:android="http://schemas.android.com/apk/res/android"
android:startOffset="5000"
android:fromXScale="3.0"
android:toXScale="0.5"
android:fromYScale="3.0"
android:toYScale="0.5"
android:duration="5000"
android:pivotX="50%"
android:pivotY="50%" >
</scale>
</set>

Please visit this link. It will really help you. Just try to understand the whole program and you'll be able to achieve what you want. I just did! Don't call the zoomImageFromThumb method from any touch or click event. You can call it from any other event, such as you want to call at the activity startup, you can call it in onCreate method. It will work.

Related

How to make moving buttons clickable

I wrote a rotation animation for a view which has 2 buttons in it, anim xml:
<rotate
xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="0"
android:toDegrees="360"
android:pivotX="50%"
android:pivotY="50%"
android:interpolator="#anim/linear_interpolator"
android:duration="10000"
android:repeatMode="restart"
android:repeatCount="infinite"
android:startOffset="0"
/>
The issue with this is that the location of the buttons seem to be fixed on the screen in the place where I put it in the XML, so when the buttons move clicking on them does nothing. I tried implementing rotation animation using RotateAnimation class but it was identical, buttons can only be clicked in the place where they were put in the XML, how to make the buttons actually movable?

i want implement animation for Floating Button

I want to give a full rotation animation to my floating button, i have the code, but its only animating like rotating half. i want rotate the floating button from a position and it should end with the same position where it started( a full rotation ) , how to do that ?
here is my code , i want some one to modify the value or code
final OvershootInterpolator interpolator = new OvershootInterpolator();
ViewCompat.animate(fab).
rotation(170f).
withLayer().
setDuration(1000).
setInterpolator(interpolator).
start();
Make rotate.xml in res/anim:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<rotate
android:fromDegrees="0"
android:toDegrees="360"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="0"
android:duration="1000" />
</set>
Then in code:
FloatingActionButton mFloatingButton = view.findViewById(R.id.myFloatingButton);
Animation mAnimation = AnimationUtils.loadAnimation(this, R.anim.rotate);
mFloatingButton.startAnimation(mAnimation);

Rotating wheel in android

My imageview consists of circle wheel as shown in below pic.I want that wheel should start rotating as soon as user presses a start button and stop rotating when user presses stop button.Is it possible programmatically?If yes,how can i do that?
Create a file named clockwise_rotation.xml and put it into /res/anim Change the duration according to your needs.
<?xml version="1.0" encoding="utf-8"?>
<rotate
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="3500"
android:fromDegrees="0"
android:interpolator="#android:anim/linear_interpolator"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="infinite"
android:startOffset="0"
android:toDegrees="360"
/>
And make these two functions that you will be calling in your two buttons
private void startAnimation(){
Animation rotation = AnimationUtils.loadAnimation(getContext(), R.anim.clockwise_rotation);
mImageView.startAnimation(rotation);
}
private void stopAnimation(){
mImageView.clearAnimation();
}

Android Animation doesn't start until second touch

I have an animation when you click on the red button on the right(area 2). When you click on the button there starts no animation. When you click on a part in area 1 the animation starts.
I don't know what I do wrong. Anyone a solution?
Animation: rotate.xml
<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="0"
android:toDegrees="90"
android:pivotX="50%"
android:pivotY="50%"
android:duration="100"
android:fillAfter="true">
</rotate>
Java-code to start animation:
Animation animturn = AnimationUtils.loadAnimation(getContext(), R.anim.rotate);
v.setAnimation(animturn);
animturn.start();
Try with Invalidate() your View (v) after start() :
...
animturn.start();
v.Invalidate();

Avoid animation automatically "unwinding"?

I've a simple view animation, but I can't see to get "rid" of the animation "unwinding" (and I can't seem to find a solution online).
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="#android:anim/linear_interpolator"
android:shareInterpolator="true" >
<scale
android:duration="250"
android:fromXScale="1"
android:fromYScale="1"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="0"
android:toXScale="1.1"
android:toYScale="1.1" />
</set>
What this does is, simply, inflates the View by 10% proportionally, from the middle.
But, when it executes, it inflates and, when it reaches the end, it deflates back. I want to avoid that -- the "unwinding" effect -- when it scales back from 110% to 100%.
How can that be done?
Edit:
I'm starting it simply with this:
Animation animation1 = AnimationUtils.loadAnimation(this, R.anim.<name>);
v.startAnimation(animation1);
The correct answer is found here: How can I animate a view in Android and have it stay in the new position/size?
It is putting this:
android:fillAfter="true"
android:fillEnabled="true"
inside the <set tag.

Categories

Resources