Find out if Android device is portrait or landscape for normal usage?

前端 未结 8 1550
情话喂你
情话喂你 2020-12-07 22:05

Is there anyway to find out if a device is portrait or landscape by default? In that I mean how you normally use the device.

Most phones have a portrait screen for

8条回答
  •  温柔的废话
    2020-12-07 23:01

    package com.android.portraitandlandscape;
    
    import android.app.Activity;
    import android.os.Bundle;
    import android.util.Log;
    import android.view.Display;
    import android.widget.Toast;
    
    public class PortraitLandScape extends Activity {
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Display display = getWindowManager().getDefaultDisplay(); 
        int width = display.getWidth();
        int height = display.getHeight();
    
        Log.v("log_tag", "display width is "+ width);
        Log.v("log_tag", "display height is "+ height);
    
        if(width

    You can try this code for checking whether device is in landscape or in portrait.

提交回复
热议问题