全屏去状态栏
- Window window = getWindow();
- window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
- window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
/设置为无标题栏
- requestWindowFeature(Window.FEATURE_NO_TITLE);
//设置为全屏模式
- getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
流的处理
- InputStream is = getResources().openRawResource(R.drawable.icon);
- //decode
- Bitmap mBitmap = BitmapFactory.decodeStream(is);
获取屏幕的宽和高
- int screenWidth;
- int screenHeight;
- WindowManager windowManager = getWindowManager();
- Display display = windowManager.getDefaultDisplay();
- screenWidth = display.getWidth();
- screenHeight = display.getHeight();
固定横竖屏
在AndroidManifest.xml里面配置一下就可以了。加入这一行android:screenOrientation="landscape"。
例如(landscape是横向,portrait是纵向):
- <activity android:name=".GamePlay"
- android:screenOrientation="portrait"></activity>
Android View添加 Listener 小技巧示例
http://rayleung.iteye.com/blog/539190
动画
- Animation rotateAnimation =
- AnimationUtils.loadAnimation(this, R.anim.rotate1);
资源
- Resources res = context.getResources();
一些牛人的blog
http://rayleung.iteye.com/
屏幕切换时的问题
获取屏幕的方向:
默认情况下,当屏幕方面切换时,activity的onCreate()方法会被重新调用,所以可以在其中通过以下代码来读取屏的方向:
- public void onCreate() {
- if(this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
- Log.i("info", "landscape");
- } else if (this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
- Log.i("info", "portrait");
- }
- }
如果在androidmanifest.xml中加入配置
android:configChanges="orientation|keyboardHidden|navigation
当屏幕翻转时,Activity就不会重复的调用onCreate()、onPause()和onResume().
而是调用onConfigurationChanged(Configuration newConfig)
测试时经常用到
- Toast.makeText(testActivity.this, "click button", Toast.LENGTH_SHORT).show();
bitmap 和 drawable 互换
- ((BitmapDrawable)res.getDrawable(R.drawable.youricon)).getBitmap();