簡體   English   中英

初始化Android動態壁紙時如何獲取屏幕的寬度和高度?

[英]How do I get the screen width and height when initializing an Android Live Wallpaper?

嘗試為Android編寫簡單的動態壁紙。 我在找出如何在初始化時捕獲屏幕尺寸時遇到了麻煩。

關於如何實現此目標的任何想法?

謝謝。

onSurfaceChanged提供寬度高度作為其參數的一部分。 當這個方法被初始化過程中調用,你可以抓住的值,並將其保存到像mWidthmHeight方法變量。 然后,您可以隨時隨地使用它們,以在代碼中使用它們。

請注意,此方法稱為AFTER onCreateonSurfaceCreated ,因此任何需要寬度和/或高度的東西都必須等到onSurfaceChanged被激發。

通過Google查看此示例以獲取更清晰的圖片: http : //developer.android.com/resources/samples/CubeLiveWallpaper/src/com/example/android/livecubes/cube1/CubeWallpaper1.html

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM