Implement Animations on different views | Techbirds

Adding Animations :-

Animations are especially useful when the screen changes state, such as when content loads or new actions become available. Animations can also add a polished look to your app, which gives your app a higher quality feel.Adding animation on any view

Here is the code to show animation on TextView :-

public class MainActivity extends Activity { Animation animBounce; TextView textanimation; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.fragment_main); textanimation=(TextView) findViewById(R.id.textView1); animBounce = AnimationUtils.loadAnimation(this,R.anim.zoom_in); textanimation.startAnimation(animBounce); }

}

for this you have to make anim folder inside res folder and make xml file(with any name) inside it.

here is the xml code for animation(zoom in 1 second)

?xml version=”1.0″ encoding=”utf-8″? set xmlns:android=”https://schemas.android.com/apk/res/android”

android:fillAfter=”true”

scale xmlns:android=”https://schemas.android.com/apk/res/android” android:duration=”1000″ android:fromXScale=”0″ android:fromYScale=”0″ android:pivotX=”50%” android:pivotY=”50%” android:toXScale=”1″ android:toYScale=”1″

/scale

/set

another xml code for shrink_to_middle.xml

set xmlns:android=”https://schemas.android.com/apk/res/android” scale android:interpolator=”@android:anim/linear_interpolator” android:fromXScale=”1.0″ android:toXScale=”1.0″ android:fromYScale=”1.0″ android:toYScale=”0.0″ android:fillAfter=”false” android:duration=”200″ / translate android:fromYDelta=”0″ android:toYDelta=”50%” android:duration=”200″/

/set

Code for grow_from_middle.xml

?xml version=”1.0″ encoding=”utf-8″? set xmlns:android=”https://schemas.android.com/apk/res/android” scale android:interpolator=”@android:anim/linear_interpolator” android:fromXScale=”1.0″ android:toXScale=”1.0″ android:fromYScale=”0.0″ android:toYScale=”1.0″ android:fillAfter=”false” android:startOffset=”200″ android:duration=”200″ / translate android:fromYDelta=”50%” android:toYDelta=”0″ android:startOffset=”200″ android:duration=”200″/

/set

Code for slide_in_left.xml

?xml version=”1.0″ encoding=”utf-8″? translate xmlns:android=”https://schemas.android.com/apk/res/android” android:duration=”@android:integer/config_longAnimTime” android:fromXDelta=”100%p”

android:toXDelta=”0%p” /

Code for slide_out_left.xml

?xml version=”1.0″ encoding=”utf-8″?