【问题标题】:how do I know what the orientation is in android? [duplicate]我怎么知道android中的方向是什么? [复制]
【发布时间】:2011-07-30 11:26:16
【问题描述】:

可能重复:
Check orientation on Android phone

我正在编写一个应用程序,它要求我的程序知道它是处于横向模式还是纵向模式之间的区别。我将如何去发现这一点。目前我正在使用 getRequestedOrientation(),但它总是返回数字 2,这基本上意味着它会根据手机的转动方式而改变(相对于 0 是横向的,或 1 是纵向的。 ) 有更好的方法吗?

【问题讨论】:

    标签: android orientation


    【解决方案1】:

    您可以使用this answer中的方法在onConfigurationChanged以外的方法中检查这一点:

    getResources().getConfiguration().orientation
    

    这将等于one of the following:

    • Configuration.ORIENTATION_PORTRAIT
    • Configuration.ORIENTATION_LANDSCAPE
    • Configuration.ORIENTATION_SQUARE

    【讨论】:

      【解决方案2】:

      onConfigurationChanged(Configurtion) 中,配置对象保存有关方向的信息。根据reference,它只能是肖像、正方形或风景。

      【讨论】:

        猜你喜欢
        • 2021-12-08
        • 2021-10-05
        • 1970-01-01
        • 2021-07-14
        • 2017-04-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多