我目前正在制作非常密集的动态壁纸,并且不能很好地处理屏幕旋转.
事实上,壁纸被破坏并显示一个空白的屏幕而没有调用onSurfaceChanged!
这是我在onSurfaceChanged方法中的内容:
@Override
public void onSurfaceChanged(SurfaceHolder holder, int format,
int width, int height) {
// TODO Auto-generated method stub
super.onSurfaceChanged(holder, format, width, height);
mRatio = (float) width / height;
if (mRatio > 1) {
orientation = 0;
}
if (mRatio < 1) {
orientation = 1;
}
setRunning(true);
Log.i(TAG, "Screen Rotation...");
mHandle.post(r);
}
Run Code Online (Sandbox Code Playgroud)
我很肯定这个方法没有被调用,因为没有日志消息.
为什么会发生这种情况以及处理屏幕旋转的一些技巧是什么?可能是我的动态壁纸如此密集,无法调用空白?
此外,也没有调用onVisibilityChanged,当我在模拟器上打开应用程序时,没有日志消息:
@Override
public void onVisibilityChanged(boolean visible) {
// TODO Auto-generated method stub
super.onVisibilityChanged(visible);
if (visible) {
setRunning(true);
Log.i(TAG, "Visible...");
mHandle.postDelayed(r, 2000);
} else { …Run Code Online (Sandbox Code Playgroud) 我目前正在制作一个密集的LiveWallpaper,它绘制到画布上.我发生了以下视频:http://www.youtube.com/watch?v = v9S5EO7CLjo.
但是,当我尝试实现硬件加速时,我遇到了错误.这是我的代码:
if (c != null && mStaticRects.length > 10 && c.isHardwareAccelerated())
drawSurfacePortrait(c);
if (c != null && mStaticRects.length < 20 && c.isHardwareAccelerated())
drawSurfaceLandscape(c);
Run Code Online (Sandbox Code Playgroud)
当我运行它时,这是相应的错误:
AndroidRuntime(382): java.lang.NoSuchMethodError: android.graphics.Canvas.isHardwareAccelerated
Run Code Online (Sandbox Code Playgroud)
最后这是我的清单......
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="stuff.of.mine"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="7" android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.VIBRATE" ></uses-permission>
<uses-feature
android:name="android.software.live_wallpaper"
android:required="true" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
***android:hardwareAccelerated="true"***>
<service
android:name=".SomeWPService"
android:permission="android.permission.BIND_WALLPAPER"
***android:hardwareAccelerated="true"***>
<intent-filter>
<action android:name="android.service.wallpaper.WallpaperService" />
</intent-filter>
<meta-data
android:name="android.service.wallpaper"
android:resource="@xml/mylwp" />
</service>
</application>
Run Code Online (Sandbox Code Playgroud)