简体   繁体   English

我在动态壁纸中的哪里使用getWindowManager()?

[英]Where do I use getWindowManager() within Live Wallpaper?

I'm getting the error "The method getWindowManager() is undefined for the type LiveWallpaperService" 我收到错误“ LiveWallpaperService类型的方法getWindowManager()未定义”

Since I'm creating an activity there is no way to reference that, how would I go around getting the screen width and height before the main class initialized within onCreateEngine() 由于我正在创建活动,因此无法引用该活动,在onCreateEngine()中初始化主类之前,如何解决屏幕宽度和高度问题?

It's the first thing that's called. 这是第一件事。 Before I was using background image for dimensions but that's proving a pain with different screen sizes. 在使用背景图像进行尺寸绘制之前,事实证明,使用不同的屏幕尺寸会很麻烦。

Can anyone please help me here? 有人可以在这里帮我吗? I've tried: 我试过了:

DisplayMetrics displaymetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);

With no luck. 没有运气。

Also tried: 还尝试了:

((Activity) getContext()).getWindowManager().getDefaultDisplay().getMetrics(metrics);

I get the error: "Activity cannot be resolved to a type" 我收到错误:“活动无法解析为一种类型”

Also: 也:

((WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE))

with : "WindowManager cannot be resolved to a type" 使用:“ WindowManager无法解析为类型”

What ever I try, where ever I place this code I always get the same error, I tried using the 无论我尝试什么,将代码放置在什么地方,我总是遇到相同的错误,我尝试使用

onSurfaceChanged

Int with width and height but they initialize too late and my application crashes, can anyone help my here thanks? Int用width和height设置,但是它们初始化得太晚了,我的应用程序崩溃了,有人可以帮助我吗?

mContext = getBaseContext();
DisplayMetrics displayMetrics = new DisplayMetrics(); 
displayMetrics = mContext.getResources().getDisplayMetrics();
mScreenWidth = displayMetrics.widthPixels;
mSreenHeight = displayMetrics.heightPixels;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM