Showing posts with label e13.1.6. Show all posts
Showing posts with label e13.1.6. Show all posts
Blink

Blink

MainActivity.java
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;
 public class MainActivity extends AppCompatActivity {
  Button btnBlink;
  @Override 
   protected void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.activity_main);
   btnBlink = (Button) findViewById(R.id.idbtnBlink);
   btnBlink.setOnClickListener(new View.OnClickListener() {
    @Override 
     public void onClick(View v) {
     ImageView image = (ImageView) findViewById(R.id.idImageView);
     Animation animation = AnimationUtils.loadAnimation(getApplicationContext(), 23 R.anim.blink);
     image.startAnimation(animation);
   }
  });
 }
}


activity_main.xml
<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" 
     android:id="@+id/activity_main" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" 
     tools:context=".MainActivity">
    
    <!-- TODO: Update blank fragment layout --> 
    <ImageView 
     android:layout_weight="4" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"
     android:id="@+id/idImageView"
     android:src="@mipmap/ic_launcher"/> 
    
    <Button 
     android:layout_margin="4dp" 
     android:layout_width="match_parent"
     android:layout_height="wrap_content" 
     android:id="@+id/idbtnBlink" 
     android:text="Blink" />
</LinearLayout>


blink.xml
<set
    xmlns:android="http://schemas.android.com/apk/res/android">  
    <alpha android:fromAlpha="0.0" 
     android:toAlpha="1.0" 
     android:interpolator="@android:anim/accelerate_interpolator" 
     android:duration="500" 
     android:repeatMode="reverse" 
     android:repeatCount="infinite"/>
</set>