Android determine screen orientation at runtime

后端 未结 6 848
清酒与你
清酒与你 2021-02-01 05:41

Here\'s a pseudo code to detect screen rotate event, and decide to retain or changes the screen orientation.

public boolean onOrientationChanges(orientation) {
          


        
6条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-01 06:06

    Check your android screen orientation at Runtime:

    ListView listView = (ListView) findViewById(R.id.listView1);
    if (getResources().getConfiguration().orientation == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) {
        //do work for landscape screen mode.
        listView.setPadding(0, 5, 0, 1);
    } else if (getResources().getConfiguration().orientation == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) {
        //Do work for portrait screen mode.
        listView.setPadding(1, 10, 1, 10);
    }
    

提交回复
热议问题