1. Android程序禁止手机自动锁屏和屏幕翻转的办法
原文:http://blog.youkuaiyun.com/zhongyuancc/archive/2010/06/10/5661985.aspx
Android开发过程中,一些程序在运行时,不希望手机自动锁屏,即保持系统的背景灯常亮,以防止程序执行时出现异常,实现起来很简单,只需要在创建Activity时,在onCreate()方法中,加入如下语句即可。
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
此外,程序运行过程中,如果将屏幕翻转,Android系统会自动改变屏幕的方向,此时,系统会重新调用onCreate()方法创建Activity,因此程序开发过程中要注意保存现场,以及屏幕的横宽比切换问题,如果不需要此功能,可以在AndroidManifest.xml文件中修改,在每个Activity中添加如下语句即可。
android:screenOrientation="portrait" //portrait代表屏幕竖直
eg:
<activity android:name="mainActivity" android:label="@String/hello" android:screenOrientation="portrait">
</activity>
2. 手动调用Jquery Mobile初始化控件用于初始化他的控件:$("#"+s_id).page();
这样可以保证在动态加载页面时保证样式等资源不丢失。
3. HTML5 canvas对象的drawImage/putImageData/getImageData 可以实现强大的绘图操作,还需要深入研究:
http://hacks.mozilla.org/2009/06/pushing-pixels-with-canvas/
http://archive.cnblogs.com/a/1968512/
http://paranimage.com/html-5-canvas-tutorials-and-examples/
4. 根据手机的分辨率导入相应的CSS:<link href="Css_320_480/Base.css" media="screen and (-webkit-device-pixel-ratio:1)" rel="stylesheet" type="text/css" />
-webkit-device-pixel-ratio的值可以在下列这个链接找到:
http://developer.android.com/reference/android/webkit/WebView.html
- The window.devicePixelRatio DOM property. The value of this property specifies the default scaling factor used for the current device. For example, if the value of window.devicePixelRatio is "1.0", then the device is considered a medium density (mdpi) device and default scaling is not applied to the web page; if the value is "1.5", then the device is considered a high density device (hdpi) and the page content is scaled 1.5x; if the value is "0.75", then the device is considered a low density device (ldpi) and the content is scaled 0.75x. However, if you specify the "target-densitydpi" meta property (discussed below), then you can stop this default scaling behavior.
- The -webkit-device-pixel-ratio CSS media query. Use this to specify the screen densities for which this style sheet is to be used. The corresponding value should be either "0.75", "1", or "1.5", to indicate that the styles are for devices with low density, medium density, or high density screens, respectively. For example:
也就是说,根据屏幕分辨率的高低来确定其值为"0.75", "1", or "1.5"之一,比如320*480的就用1.
另一个文档:
http://zsefvlol.blogbus.com/logs/80558539.html