After some searching on internet, i found this code could help solve my problem:
DisplayMetrics metrics = new DisplayMetrics();When i was still extends the Activity class, i can use getWindowManager() method since that is a method in Activity class. you can use that within the sub-class.
getActivity().getWindowManager().getDefaultDisplay().getMetrics(metrics);
double screenWidth = metrics.widthPixels;
To use the getWindowManager() method in fragment, you need to use the getActivity() to get the Activity which your fragment is currently associated with.
Refernece:
http://stackoverflow.com/questions/8833825/error-getting-window-size-on-android-the-method-getwindowmanager-is-undefined
http://developer.android.com/reference/android/app/Activity.html
http://developer.android.com/reference/android/app/Fragment.html
No comments :
Post a Comment