1.在界面中按返回键判断某个控件的可见性,如果可见,则用动画让其消失,应用并不退出。
Onkeydown方法中:
if(keyCode == 4){
if(slidingMenu.getVisibility() == View.VISIBLE){
//退出的动画
AnimationSet animationSet = new AnimationSet(true);
TranslateAnimation animation = new TranslateAnimation(0,-280, 0, 0);
animation.setDuration(500);
animationSet.addAnimation(animation);
slidingMenu.startAnimation(animationSet);
slidingMenu.setVisibility(View.GONE);
return true; //如果控件在界面是可见的话,按返回键让其消失,应用并不退出
}
}
2.控制界面的延时跳转
public class WelcomeActivity extends Activity{
private Handler mHandler = new Handler() {
public void handleMessage(android.os.Message msg) {
goMain();
}};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.welcome);
}
@Override
protected void onResume() {
super.onResume();
mHandler.sendEmptyMessageDelayed(0, 3000);
}
/**
* 跳转到主界面
*/
private void goMain() {
Intent intent = new Intent(WelcomeActivity.this, MainActivity.class);
startActivity(intent);
this.finish();
}}
3.获取屏幕宽和高
DisplayMetrics dm = new DisplayMetrics();
this.getWindowManager().getDefaultDisplay().getMetrics(dm);
screenWidth = dm.widthPixels;
screenHeight = dm.heightPixels;
4.private protected public的区别
public
公共,加上这个修饰的类或属性,可以在同一个包或者别的包里面访问
private
私有的,加上这个修饰的类或属性,只能在同类里访问,同包和别的包不能访问
protected
保护,加上这个修饰的类或属性,只能在同类和同包访问,别的包不能访问
Android 开发技巧总结(三),布布扣,bubuko.com