package com.anilkrishna.cricketscores;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
TextView start;
TextView credit;
boolean flag=false;
public void startApp()
{
start=(TextView)findViewById(R.id.start);
start.animate().alpha(1).scaleX(1f).scaleY(1f).setDuration(3000);
credit=(TextView)findViewById(R.id.credit);
credit.animate().alpha(1).scaleX(1f).scaleY(1f).setDuration(3000);
credit.animate().alpha(1).scaleX(1f).scaleY(1f).setDuration(2000);
start.setVisibility(View.GONE);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
startApp();
}
}
我的要求是应用程序必须显示文本视图,动画然后消失,但动画没有发生,并且应用程序启动后TextViews不可见。
答案 0 :(得分:1)
你甚至在有机会动画之前就开始设置GONE。考虑在Activity上实现Animation.AnimationListener,然后在onAnimationEnd方法中设置可见性。
public class MainActivity extends AppCompatActivity implements Animation.AnimationListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
animation = AnimationUtils.loadAnimation(this, R.anim.some_animation);
animation.setAnimationListener(this);
}
@Override
protected void onStart() {
super.onStart();
start.startAnimation(animation);
}
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
start.setVisibility(Visibility.GONE);
}
@Override
public void onAnimationRepeat(Animation animation) {
}
}