Android is a simple way to determine whether a screen is landscape or portrait

  • 2020-06-03 08:15:39
  • OfStack

This article describes a common technique code of Android, which is mainly used to judge whether the mobile phone screen is horizontal or vertical. After judging whether the screen is horizontal or vertical, you can make corresponding response to the program. The example code is just to judge whether the screen is portrait.

The specific program code is as follows:


package com.lurencun.cfuture09.androidkit.util.ui;
import android.content.Context;
import android.content.res.Configuration;
public class ActivityUtil {
 /**
 *  Returns whether the current screen is portrait. 
 * @param context
 * @return  Returns if and only if the current screen is portrait true, Otherwise returns false . 
 */
 public static boolean isScreenOriatationPortrait(Context context) {
 return context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT;
 }
}


Related articles: