一.splash页面并进入主界面
*布局:*
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/rl_root"
android:background="@drawable/background_splash"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.administrator.xw.SplashActivity">
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:src="@drawable/background_splash" />
</RelativeLayout>
逻辑
public class SplashActivity extends Activity {
private RelativeLayout rlRoot;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
rlRoot = (RelativeLayout) findViewById(R.id.rl_root);
// 旋转动画
RotateAnimation animRotate = new RotateAnimation(0, 360,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
0.5f);
animRotate.setDuration(1000);// 动画时间
animRotate.setFillAfter(true);// 保持动画结束状态
// 缩放动画
ScaleAnimation animScale = new ScaleAnimation(0, 1, 0, 1,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
0.5f);
animScale.setDuration(1000);
animScale.setFillAfter(true);// 保持动画结束状态
// 渐变动画
AlphaAnimation animAlpha = new AlphaAnimation(0, 1);
animAlpha.setDuration(2000);// 动画时间
animAlpha.setFillAfter(true);// 保持动画结束状态
// 动画集合
AnimationSet set = new AnimationSet(true);
set.addAnimation(animRotate);
set.addAnimation(animScale);
set.addAnimation(animAlpha);
// 启动动画
rlRoot.startAnimation(set);
set.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationRepeat(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
// 动画结束,跳转页面
// 如果是第一次进入, 跳新手引导
Intent intent = new Intent(getApplicationContext(),
MainActivity.class);
startActivity(intent);
finish();// 结束当前页面
}
});
}
}
二.左滑sliding menu
首先导入sliding menu库
步骤:1.改sliding menu中library为slidingmenulibrary
2.File–Import Module导入
3.修改SlidingMenu里的build.gradle文件(视自己个人情况改动)
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.0.0'
}
}
apply plugin: 'android-library'
dependencies {
compile 'com.android.support:support-v4:2.2.2'//改动
compile 'com.android.support:appcompat-v7:24.2.1'//改动
}
android {
compileSdkVersion 24//改动
buildToolsVersion "24.0.3"//改动
defaultConfig {
minSdkVersion 23//改动
targetSdkVersion 24//改动
}
4.修改app目录下的build.gradle文件
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
compile project(':SlidingMenu')//加上这句~
}
5.万一出现(float)FloatMath错误,将其改为(float)Math
三.开始写左滑栏left_menu
布局
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ff0000">
</LinearLayout>
逻辑
setBehindContentView(R.layout.left_menu);
SlidingMenu slidingMenu = getSlidingMenu();
slidingMenu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);//全屏触摸
slidingMenu.setBehindOffset(200);//屏幕预留200像素宽度
**四.去掉标题栏**
必须要在setContentView上面
requestWindowFeature(Window.FEATURE_NO_TITLE);// 去掉标题,