Linh Tran
Linh Tran

Reputation: 21

why getHeight() or getWidth() not work in Android Studio

FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();

WindowManager wm = getWindowManager();
Display d = wm.getDefaultDisplay();
if(d.getWidth()>d.getHeight()){

}

Why getWidth() not work? :(

Upvotes: 0

Views: 1464

Answers (1)

Tamil Selvan C
Tamil Selvan C

Reputation: 20209

getHeight() and getWidth() was deprecated in API level 13. Use getSize(Point) instead.

See http://developer.android.com/reference/android/view/Display.html#getHeight() and http://developer.android.com/reference/android/view/Display.html#getWidth()

try

WindowManager wm = getWindowManager();
Display d = wm.getDefaultDisplay();

Point point = new Point();
d.getSize(point);
if( d.x > d.y ) {
} 

Upvotes: 2

Related Questions