关键字:android keyguard 锁屏程序不能 全屏显示 解锁界面 变小
![](http://hi.csdn.net/attachment/201112/5/0_132307573383i4.gif)
解法二:这个方法解了我们的问题,测试这么长时间还没出现问题:(推荐)
![](http://hi.csdn.net/attachment/201112/5/0_13230760279bq7.gif)
![](http://hi.csdn.net/attachment/201112/5/0_1323076085qaF6.gif)
frameworks\base\policy\src\com\android\internal\policy\impl\KeyguardViewManager.java.
android2.3.4_GB_T34H\frameworks\base\core\java\android\content\res\CompatibilityInfo.java
diff --git a/phone/com/android/internal/policy/impl/KeyguardViewManager.java b/phone/com/android/internal/policy/impl/KeyguardViewManager.java
index ba1d7f5..38bf161 100644
--- a/phone/com/android/internal/policy/impl/KeyguardViewManager.java
+++ b/phone/com/android/internal/policy/impl/KeyguardViewManager.java
@@ -28,6 +28,8 @@ import android.view.ViewGroup;
import android.view.ViewManager;
import android.view.WindowManager;
import android.widget.FrameLayout;
+import android.view.Display;
+import android.util.DisplayMetrics;
/**
* Manages creating, showing, hiding and resetting the keyguard.Calls back
@@ -97,9 +99,21 @@ public class KeyguardViewManager implements KeyguardWindowController {
if (mKeyguardHost == null) {
if (DEBUG) Log.d(TAG, "keyguard host is null, creating it...");
+WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
+DisplayMetricsdm = new DisplayMetrics();
+wm.getDefaultDisplay().getMetrics(dm);
+Display display = wm.getDefaultDisplay();
+
+int statusBarHeight = (int)Math.ceil( 25 * dm.density);
+int height = display.getHeight();
+int width = display.getWidth();
+
+Log.i(TAG, "Display width = " + width);
+Log.i(TAG, "Display height = " + height);
+Log.i(TAG, "Statusbar height = " + statusBarHeight);
+
mKeyguardHost = new KeyguardViewHost(mContext, mCallback);
-final int stretch = ViewGroup.LayoutParams.MATCH_PARENT;
int flags = WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN
| WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER
| WindowManager.LayoutParams.FLAG_KEEP_SURFACE_WHILE_ANIMATING
@@ -109,7 +123,7 @@ public class KeyguardViewManager implements KeyguardWindowController {
flags |= WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
}
WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
-stretch, stretch, WindowManager.LayoutParams.TYPE_KEYGUARD,
+width, (height - statusBarHeight), WindowManager.LayoutParams.TYPE_KEYGUARD,
flags, PixelFormat.TRANSLUCENT);
lp.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN;
lp.windowAnimations = com.android.internal.R.style.Animation_LockScreen;
解法二:这个方法解了我们的问题,测试这么长时间还没出现问题:(推荐)
1,android2.3.4_GB_T34H\frameworks\base\core\java\android\content\res
修改frameworks/base/core/java/android/content/res/CompatibilityInfo.java中的如下部分:
public static void updateCompatibleScreenFrame(DisplayMetrics dm, int orientation,
Rect outRect) {
int width = dm.widthPixels;
int portraitHeight = (int) (DEFAULT_PORTRAIT_HEIGHT * dm.density + 0.5f);
int portraitWidth = (int) (DEFAULT_PORTRAIT_WIDTH * dm.density + 0.5f);
if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
int xOffset = (width - portraitHeight) / 2 ;
outRect.set(xOffset, 0, xOffset + portraitHeight, portraitWidth);
} else {
int xOffset = (width - portraitWidth) / 2 ;
outRect.set(xOffset, 0, xOffset + portraitWidth, portraitHeight);
}
把上面这段程序改为下面这一段程序:
==》
public static void updateCompatibleScreenFrame(DisplayMetrics dm, int orientation,
Rect outRect) {
int width = dm.widthPixels;
int portraitHeight = (int) (DEFAULT_PORTRAIT_HEIGHT * dm.density + 0.5f);
int portraitWidth = (int) (DEFAULT_PORTRAIT_WIDTH * dm.density + 0.5f);
if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
int xOffset = (width - portraitHeight) / 2 ;
+outRect.set(0, 0, 0 + dm.widthPixels, dm.heightPixels); //新加入代码
- outRect.set(xOffset, 0, xOffset + portraitHeight, portraitWidth); //删除原来代码部分
} else
{
int xOffset = (width - portraitWidth) / 2 ;
+outRect.set(0, 0, 0 + dm.widthPixels, dm.heightPixels); //新加入代码
- outRect.set(xOffset, 0, xOffset + portraitWidth, portraitHeight); //删除代码部分
}
}
红色部分是我们改动的代码人,“-“ 是我们去除原始代码:
frameworks/base/core/java/android/content/res/CompatibilityInfo.java这里面,DEFAULT_PORTRAIT_HEIGHT /DEFAULT_PORTRAIT_WIDTH这两个值比较重要。
打印出一些值,下面分析:
dm.density = 1.5
portraitHeight = 720
portraitWidth = 480
dm.widthPixels = 1024
dm.heightPixels= 600
width = dm.widthPixels
其实出现偏移的原因是:
假设横屏:
不正常情况下分析 :
xOffset = (width - portraitHeight) / 2=(1024-720)/ 2 = 152
所在在程序中原来的代码是
outRect.set(xOffset, 0, xOffset + portraitHeight, portraitWidth);//原始代码
outRect.set(152,0, 152+ 720, 480);
xOffset所以有了左右的偏移,如下图所示:
改动后,正常情况下分析:
改动后计算:
outRect.set(0, 0, 0 + dm.widthPixels, dm.heightPixels);
outRect.set(0, 0, 0 +1024, 600);
![](http://hi.csdn.net/attachment/201112/5/0_1323076265S5nr.gif)