【问题标题】:The Activity flag ScreenOrientation.Portrait does not existActivity 标志 ScreenOrientation.Portrait 不存在
【发布时间】:2014-05-14 19:39:51
【问题描述】:

我在 Activity 标志中添加了以下代码,它说它不存在。

    ScreenOrientation = ScreenOrientation.Portrait

“ScreenOrientation.Portrait”是它说不存在的唯一部分。我必须添加另一个参考吗?我必须在其他地方定义它吗?其他论坛只是说添加上面的代码。感谢那些花时间的人。

【问题讨论】:

    标签: android mobile xamarin


    【解决方案1】:

    使用以下活动标志,您可以强制活动的纵向方向:

    [Activity (ScreenOrientation = Android.Content.PM.ScreenOrientation.Portrait)]          
    public class YourActivity
    

    【讨论】:

    • 谢谢!!我很感激
    【解决方案2】:

    如果您想在代码中更改活动布局,请使用:

    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    

    【讨论】:

      【解决方案3】:

      androidManifest.xml 中的 Activity 语法实际上如下所示:

       android:screenOrientation=[
                "unspecified" | "behind" |
                "landscape" | "portrait" |
                "reverseLandscape" | "reversePortrait" |
                "sensorLandscape" | "sensorPortrait" |
                "userLandscape" | "userPortrait" |
                "sensor" | "fullSensor" | "nosensor" |
                "user" | "fullUser" | "locked"]
      

      正如 android 开发人员的清单/活动元素中所述:http://developer.android.com/guide/topics/manifest/activity-element.html

      要使用 xamaring 实现这一点(您不应编辑 androidManifest.xml),您需要在类的声明中添加 自定义属性,以通知编译器生成正确的属性<activity .../> 标签:

      [Activity (Label="MyActivityName", 
          ScreenOrientation = Android.Content.PM.ScreenOrientation.Portrait)]
      public class MyActivity : Activity 
      [...]
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2015-12-06
        • 1970-01-01
        • 2014-08-25
        • 2019-05-26
        • 2010-12-01
        • 1970-01-01
        • 2012-02-29
        相关资源
        最近更新 更多