在学习的时候记录每个小的结果,日积月累吧。有些参考:http://blog.csdn.net/liu537192/article/details/39717201
下面是自己敲代码。
1.开始界面
package com.example.appstart;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
public class StartActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final View view=View.inflate(this, R.layout.start_main, null);
setContentView(view);
AlphaAnimation aa=new AlphaAnimation(0.1f, 1.0f);
aa.setDuration(2000); //变亮的速度,越大越慢
view.startAnimation(aa);
aa.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation arg0) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationRepeat(Animation arg0) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationEnd(Animation arg0) {
// TODO Auto-generated method stub
ViewChange(); //调用界面变换的方法
}
/**
* 界面变换的方法
*/
private void ViewChange() {
// TODO Auto-generated method stub
Intent intent=new Intent();
intent.setClass(StartActivity.this, MainActivity.class);
startActivity(intent);
StartActivity.this.finish(); //结束前面的开始界面
}
});
}
2.要转换的到的界面
package com.example.appstart;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
3.最后AndroidManife.xml的配置
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.appstart"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.appstart.MainActivity"
android:label="@string/app_name" >
注意这里要注释掉,不然出错
<!-- <intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter> -->
</activity>
<activity
android:name="com.example.appstart.StartActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>