you cant run an animation in oncreate as it is not yet attached to the view, so to run a start up animation override this method.
@Override
public void onWindowFocusChanged(boolean hasFocus) {
RunAnimations();
super.onWindowFocusChanged(hasFocus);
}
try this in you xml anim
android:repeatCount="0"
im not sure if you need to set oneshot for scaling but my onetime startup animation list looks like this:
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="true">
<item android:drawable="@drawable/artsun" android:duration="100"/>
<item android:drawable="@drawable/artsun2" android:duration="100"/>
<item android:drawable="@drawable/artsun3" android:duration="100"/>
<item android:drawable="@drawable/artsun4" android:duration="100"/>
</animation-list>
android documentation clearly states to use a startup animation you override the above method, not ONSTART() or ONCREATE()!
@Override
public void onWindowFocusChanged(boolean hasFocus) {
RunAnimations();
super.onWindowFocusChanged(hasFocus);
}
can go anywhere in your main activity, then just create the run animations method and in it put anything you want to start
private void RunAnimations() {
Animation a = AnimationUtils.loadAnimation(this, R.anim.fade);
/* a.reset();
logoImage = (ImageView) findViewById(R.id.dopescrawl);
logoImage.setBackgroundResource(R.drawable.dopesplash);
logoAnimation = (AnimationDrawable) logoImage.getBackground();
logoImage.clearAnimation();
logoImage.startAnimation(a);
*/
a = AnimationUtils.loadAnimation(this, R.anim.slide);
a.reset();
ImageView title = (ImageView) findViewById(R.id.dopescrawl);
title.clearAnimation();
title.startAnimation(a);
//logoAnimation.start();
}
whole class as follows
public class Splash extends Activity {
/** Called when the activity is first created. */
//MediaPlayer mpSplash;
AnimationDrawable logoAnimation;
ImageView logoImage;
ProgressBar progressBar1;
View ticker;
ImageView gplay;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.splash);
progressBar1=(ProgressBar)findViewById(R.id.progressBar1);
progressBar1.setVisibility(View.INVISIBLE);
gplay=(ImageView) findViewById(R.id.gplay);
ticker = (View) findViewById(R.id.ticker);
ticker.setFocusable(true);
ticker.requestFocus();
ticker.setSelected(true);
this.gplay.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=com.gmaninc.dopewars"));
startActivity(browserIntent);
}
});
}
@Override
protected void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
//mpSplash.release();
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
//mpSplash.pause();
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
//mpSplash.start();
}
@Override
protected void onStart() {
// TODO Auto-generated method stub
super.onStart();
}
@Override
protected void onStop() {
// TODO Auto-generated method stub
super.onStop();
}
@Override
public void onWindowFocusChanged(boolean hasFocus) {
RunAnimations();
super.onWindowFocusChanged(hasFocus);
}
private void RunAnimations() {
Animation a = AnimationUtils.loadAnimation(this, R.anim.fade);
/* a.reset();
logoImage = (ImageView) findViewById(R.id.dopescrawl);
logoImage.setBackgroundResource(R.drawable.dopesplash);
logoAnimation = (AnimationDrawable) logoImage.getBackground();
logoImage.clearAnimation();
logoImage.startAnimation(a);
*/
a = AnimationUtils.loadAnimation(this, R.anim.slide);
a.reset();
ImageView title = (ImageView) findViewById(R.id.dopescrawl);
title.clearAnimation();
title.startAnimation(a);
//logoAnimation.start();
}
@Override
public boolean onTouchEvent(MotionEvent event) {
progressBar1.setVisibility(View.VISIBLE);
progressBar1.setIndeterminate(true);
startActivity(new Intent("com.gmaninc.dopewarsfree.MG"));
return super.onTouchEvent(event);
}
}