为什么getHeight()或getWidth()在Android Studio中不起作用

时间:2015-06-27 07:01:25

标签: android-fragments

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

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

}

为什么getWidth()不起作用? :(

1 个答案:

答案 0 :(得分:2)

在API级别13中不推荐使用getHeight()和getWidth()。请改用getSize(Point)

请参阅http://developer.android.com/reference/android/view/Display.html#getHeight()http://developer.android.com/reference/android/view/Display.html#getWidth()

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

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