Code for Text Shake Animation , left-to-right Animation , right-to-left Animation in Android

package com.example.marqueetext;

import android.app.Activity;
import android.os.Bundle;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.TranslateAnimation;
import android.widget.TextView;


public class MainActivity extends Activity {

Animation shake;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
       
        TextView tv1 = (TextView) this.findViewById(R.id.TextView01);
        Animation animationToLeft = new TranslateAnimation(800, -600, 0, 0);
        animationToLeft.setDuration(11000);
        animationToLeft.setRepeatMode(Animation.RESTART);
        animationToLeft.setRepeatCount(Animation.INFINITE);
             
        TextView tv2 = (TextView) this.findViewById(R.id.TextView02);
        tv2.setFocusable(true);  // Set focus to the textview

      //Load Shake Animation xml file here
        shake = AnimationUtils.loadAnimation(this, R.anim.shakeanim);
      //Animation works here...
        tv2.startAnimation(shake);
       
        TextView tv3 = (TextView) this.findViewById(R.id.TextView03);
        Animation animationToRight = new TranslateAnimation(-800,600, 0, 0);
        animationToRight.setDuration(12000);
        animationToRight.setRepeatMode(Animation.RESTART);
        animationToRight.setRepeatCount(Animation.INFINITE);

        tv1.setAnimation(animationToLeft);
        tv3.setAnimation(animationToRight);
    }    
}


res/anim/shakeanim.xml :
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="20000"
    android:fromXDelta="0"
    android:interpolator="@anim/cycles"
    android:toXDelta="20" />


res/anim/cycles.xml :
<?xml version="1.0" encoding="utf-8"?>
<cycleInterpolator xmlns:android="http://schemas.android.com/apk/res/android"
    android:cycles="60" />


res/layout/activity_main.xml :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" 
    android:orientation="vertical">
    <TextView
        android:id="@+id/TextView01"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"        
        android:text="Please Contact : " />    
    <TextView
        android:id="@+id/TextView02"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"        
        android:text="Pavan Tilak"
        android:gravity="center_horizontal" />    
    <TextView
        android:id="@+id/TextView03"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"        
        android:text="Website : pavantilak.blogspot.com" />
</LinearLayout>









Comments

Popular posts from this blog

Custom Dialog with no title and full screen in Android

Best working code to set Date limits on Date Picker Dialog,in Android

code to display .pdf,.text,.DOC,.DOCX,.doc extension files exists in SDCard