刚开始学安卓,遇到个问题:就是 rl_splash.startAnimation(aa); 没有运行动画 问一下什么原因?
public class SplashActivity extends Activity {
private TextView tv_splash_version;
private RelativeLayout rl_splash;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//设置为无标题栏
requestWindowFeature(Window.FEATURE_NO_TITLE);
//设置为全屏模式
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_splash);
rl_splash = (RelativeLayout) findViewById(R.id.rl_splash);
tv_splash_version = (TextView)findViewById(R.id.tv_splash_version);
tv_splash_version.setText(“版本号:” + getVersion());
AlphaAnimation aa = new AlphaAnimation(0.3f, 1.0f);
aa.setDuration(2000);
rl_splash.startAnimation(aa);
public class SplashActivity extends Activity {
private TextView tv_splash_version;
private RelativeLayout rl_splash;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//设置为无标题栏
requestWindowFeature(Window.FEATURE_NO_TITLE);
//设置为全屏模式
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_splash);
rl_splash = (RelativeLayout) findViewById(R.id.rl_splash);
tv_splash_version = (TextView)findViewById(R.id.tv_splash_version);
tv_splash_version.setText(“版本号:” + getVersion());
AlphaAnimation aa = new AlphaAnimation(0.3f, 1.0f);
aa.setDuration(2000);
rl_splash.startAnimation(aa);
loadMainUI();// 进入程序主界面
}
//获取当前应用程序的版本号
private String getVersion() {
PackageManager pm = this.getPackageManager();
try{
PackageInfo info = pm.getPackageInfo(getPackageName(),0);
return info.versionName;
}catch (Exception e){
e.printStackTrace();
return “”;
}
}
private void loadMainUI() {
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
finish();// 把当前的Activity从任务栈里面移除
}
}
解决方案
20
有动画效果啊,只是你在动画开始的时候就 startActivity(intent);
finish();了进入下一个activity了,你当然看不出效果了。
rl_splash.startAnimation(aa);
loadMainUI();可以说是同时执行的了,你可以监听动画,在动画结束在执行 loadMainUI();
监听动画就是aa.set………那什么,就和按键监听样
finish();了进入下一个activity了,你当然看不出效果了。
rl_splash.startAnimation(aa);
loadMainUI();可以说是同时执行的了,你可以监听动画,在动画结束在执行 loadMainUI();
监听动画就是aa.set………那什么,就和按键监听样
20
可以写个定时器,过几秒再执行跳转逻辑
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
startActivity(new Intent(SplashActivity.this,MainActivity.class));
finish();
}
}, 6000);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
startActivity(new Intent(SplashActivity.this,MainActivity.class));
finish();
}
}, 6000);