我正在寫一個Android應用程序,模擬鼠標。 我用代碼pocketmagic.com遊標覆蓋 而在我的Droid Maxx的(4.4.4),它的工作原理 但在Minix的NEO X5微型(4.4.2)(機頂盒)不 下面的代碼故障與重疊窗口
mView = new OverlayView(this);
WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,//TYPE_SYSTEM_ALERT,//TYPE_SYSTEM_OVERLAY,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE |
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN, //will cover status bar as well!!!
PixelFormat.TRANSLUCENT);
params.gravity = Gravity.LEFT | Gravity.TOP;
params.setTitle("Cursor");
WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);
wm.addView(mView, params);
而且
class OverlayView extends ViewGroup {
private Paint mLoadPaint;
boolean mShowCursor;
Bitmap cursor;
public int x = 0,y = 0;
public void Update(int nx, int ny) {
x = nx; y = ny;
}
public void ShowCursor(boolean status) {
mShowCursor = status;
}
public boolean isCursorShown() {
return mShowCursor;
}
public OverlayView(Context context) {
super(context);
cursor = BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_cursor);
mLoadPaint = new Paint();
mLoadPaint.setAntiAlias(true);
mLoadPaint.setTextSize(10);
mLoadPaint.setARGB(255, 255, 0, 0);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
//canvas.drawText("Hello World", 0, 0, mLoadPaint);
if (mShowCursor) canvas.drawBitmap(cursor,x,y,null);
}
@Override
protected void onLayout(boolean arg0, int arg1, int arg2, int arg3, int arg4) {
}
@Override
public boolean onTouchEvent(MotionEvent event) {
return true;
}
}
發現這是**實際工作**,但只有在屏幕的左側部分(0-855像素)也是「顯示屏幕重繪」在開發中選項強制屏幕部分比右邊部分更頻繁地閃爍。屏幕分辨率爲1920×1080 –