Top Menu

Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Friday 18 July 2014

Animate TextView in Android Application

Create a new Project "AnimatedTextSample"

main.xml

Add a button to create animation text:

<RelativeLayout 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"
    tools:context="com.example.animatetextview.MainActivity" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/textView1"
        android:layout_below="@+id/textView1"
        android:layout_marginTop="22dp"
        android:text="Animate" />

</RelativeLayout>

MainActivity.java

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
      
        Button btn = (Button) findViewById(R.id.button1);
        final TextView textView = (TextView) findViewById(R.id.textView1);
      
        btn.setOnClickListener(new OnClickListener() {
          
            @Override
            public void onClick(View v) {
                textView.setText("Welcome to Android!");
                textView.startAnimation(AnimationUtils.loadAnimation(MainActivity.this, android.R.anim.slide_in_left));
            }
        });
    }

No comments:

Post a Comment