代码之家  ›  专栏  ›  技术社区  ›  Shainu Thomas

处理屏幕方向?

  •  -2
  • Shainu Thomas  · 技术社区  · 7 年前

    加载页面时,首先以横向_模式加载,几秒钟后,方向更改为纵向_模式值

    protected void onCreate(Bundle savedInstanceState)
    {
    
        super.onCreate();
    
        setContentView(R.layout.layout);
    
        if(orientation.equals("true")) 
        {
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        }
        else
        {
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        }
    }
    
    3 回复  |  直到 7 年前
        1
  •  0
  •   Burhanuddin Rashid Abdilahi    7 年前

    默认情况下,无论设备处于当前方向,它都将以该模式打开活动。没有具体的方法来处理这个问题

    当您在活动中以编程方式更改方向时,该方向将仅在活动后执行 onCreate() 方法

    Splash Screen Image for landscape and Portrait using Theme

        2
  •  0
  •   Sara Tirmizi    7 年前

    @Shainu集合

     android:screenOrientation = "user"
    

    更新您的首选项 方向 在开始活动之前。 用户当前的首选方向。

    https://developer.android.com/guide/topics/manifest/activity-element.html

        3
  •  0
  •   Shainu Thomas    7 年前

    对我来说,最好的解决方案是在调用super之前处理屏幕方向。onCreate();