获取屏幕宽度和高度并判断横竖屏

void test(){
    Display display = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay();
    int width = display.getWidth();
    int height = display.getHeight();
    int orientation = display.getOrientation();
    switch(orientation){
        case Configuration.ORIENTATION_PORTRAIT:
        //....
        break;
        case Configuration.ORIENTATION_LANDSCAPE:
        //...
        break;
        default :
        //...
     }
}

你可能感兴趣的:(android Display)