android开发——小细节笔记

[b]全屏去状态栏[/b]
    Window window = getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);

[b]/设置为无标题栏[/b]

requestWindowFeature(Window.FEATURE_NO_TITLE);


[b]//设置为全屏模式[/b]

getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);  


[b]流的处理[/b]
InputStream is = getResources().openRawResource(R.drawable.icon);  
//decode
Bitmap mBitmap = BitmapFactory.decodeStream(is);


[b]获取屏幕的宽和高[/b]
int screenWidth;  
int screenHeight;

WindowManager windowManager = getWindowManager();

Display display = windowManager.getDefaultDisplay();
screenWidth = display.getWidth();
screenHeight = display.getHeight();


[b]固定横竖屏[/b]
在AndroidManifest.xml里面配置一下就可以了。加入这一行android:screenOrientation="landscape"。
例如(landscape是横向,portrait是纵向):
<activity android:name=".GamePlay"  
android:screenOrientation="portrait"></activity>


[b]Android View添加 Listener 小技巧示例[/b]
http://rayleung.iteye.com/blog/539190

动画
Animation rotateAnimation =
AnimationUtils.loadAnimation(this, R.anim.rotate1);

资源
Resources res = context.getResources();



一些牛人的blog
http://rayleung.iteye.com/


[b]屏幕切换时的问题[/b]
获取屏幕的方向:

默认情况下,当屏幕方面切换时,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();
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值