Last active
December 19, 2015 22:32
-
-
Save LuizGadao/c3c8db1ed0c408b90366 to your computer and use it in GitHub Desktop.
Android framgemt with imageview animate with resource animation.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package br.com.luizgadao.animation; | |
import android.support.v4.app.Fragment; | |
import android.os.Bundle; | |
import android.view.LayoutInflater; | |
import android.view.View; | |
import android.view.ViewGroup; | |
import android.view.animation.Animation; | |
import android.view.animation.AnimationUtils; | |
import android.widget.Button; | |
import android.widget.ImageView; | |
/** | |
* A placeholder fragment containing a simple view. | |
*/ | |
public class MainActivityFragment extends Fragment { | |
ImageView ball; | |
Button btnScale, btnRotate, btnTransform, btnAlpha; | |
Animation animApha, animRotate, animTrans, animScale; | |
public MainActivityFragment() { | |
} | |
@Override | |
public View onCreateView(LayoutInflater inflater, ViewGroup container, | |
Bundle savedInstanceState) { | |
View v = inflater.inflate(R.layout.fragment_main, container, false); | |
ball = (ImageView) v.findViewById(R.id.ball); | |
btnAlpha = (Button) v.findViewById(R.id.btnAlpha); | |
btnRotate = (Button) v.findViewById(R.id.btnRotate); | |
btnTransform = (Button) v.findViewById(R.id.btnTrans); | |
btnScale = (Button) v.findViewById(R.id.btnScale); | |
btnAlpha.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
animApha = loadAnimation(R.anim.alpha); | |
ball.startAnimation(animApha); | |
} | |
}); | |
btnRotate.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
animRotate = loadAnimation(R.anim.rotate); | |
ball.startAnimation(animRotate); | |
} | |
}); | |
btnTransform.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
animTrans = loadAnimation(R.anim.translate); | |
ball.startAnimation(animTrans); | |
} | |
}); | |
btnScale.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
animScale = loadAnimation(R.anim.scale); | |
ball.startAnimation(animScale); | |
} | |
}); | |
return v; | |
} | |
private Animation loadAnimation(int resAnim){ | |
return AnimationUtils.loadAnimation(getContext(), resAnim); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment