如何学Android

首先,你要知道Android的主窗口,在adminifest文件里找android  name ,再从这个窗口入手,依据各个功能展开,有几个类要很好理解,比如surface 类,util类,

public class Act_Main extends Activity {private int flag;
private SV_main sv_main;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
flag = Settings.System.getInt(getContentResolver(), Settings.System.ACCELEROMETER_ROTATION, 0);
if (flag == 0) {
Settings.System.putInt(getContentResolver(), Settings.System.ACCELEROMETER_ROTATION, 1);
}
if(getGLVersion()<2){
Toast.makeText(this, "显卡太低!!!", Toast.LENGTH_LONG).show();
System.exit(0);
}
initScreen();
sv_main = new SV_main(this);
setContentView(sv_main);
sv_main.requestFocus();
sv_main.setFocusableInTouchMode(true);
}

@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
}

@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
}


private void initScreen() {
// TODO Auto-generated method stub
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
int tempHeight = (int) (SCREEN_HEIGHT = dm.heightPixels);
int tempWidth = (int) (SCREEN_WIDTH = dm.widthPixels);
if (tempHeight < tempWidth) {
SCREEN_HEIGHT = tempHeight;
SCREEN_WIDTH = tempWidth;
} else {
SCREEN_HEIGHT = tempWidth;
SCREEN_WIDTH = tempHeight;
}
float ratio = SCREEN_HEIGHT / SCREEN_WIDTH;
if (ratio < 0.5624f) {
FINAL_HEIGHT = SCREEN_HEIGHT;
FINAL_WIDTH = SCREEN_HEIGHT / 0.5624f;
} else {
FINAL_WIDTH = SCREEN_WIDTH;
FINAL_HEIGHT = SCREEN_WIDTH * 0.5624f;
}
}


public int getGLVersion() {
ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
ConfigurationInfo info = am.getDeviceConfigurationInfo();
int majorVersion = info.reqGlEsVersion;
majorVersion = majorVersion >>> 16;
return majorVersion;
}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.act__main, menu);
return true;
}


public void exitRelease() {
System.exit(0);
}


@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
// TODO Auto-generated method stub
exitRelease();
return super.onKeyDown(keyCode, event);
}




}

特别是要注意安卓包,它是很重要的,因为它告诉你引进了哪些信息和方法

posted @ 2015-04-11 22:33  Anzhongliu  阅读(145)  评论(0编辑  收藏  举报