문제

I added the following code to the Activity flag and it says that it does not exist.

    ScreenOrientation = ScreenOrientation.Portrait

"ScreenOrientation.Portrait" is the only part that it says does not exist. Do I have to add another reference? Do i have to define it somewhere else? Other forums just said to add the code above. Thank you to those that took the time.

도움이 되었습니까?

해결책

Using the following Activity flag you can force Portrait orientation for the activity:

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

다른 팁

If you want to change activity layout in code, use this:

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

The activity's syntax in the androidManifest.xml actually looks like this:

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

as it is described at android developers' manifest/activity element: http://developer.android.com/guide/topics/manifest/activity-element.html

To achieve this using xamaring (where you shouldn't edit your androidManifest.xml), you need to add a custom attribute to your class's declaration, to notify the compiler to generate the proper attributes for the <activity .../> tag:

[Activity (Label="MyActivityName", 
    ScreenOrientation = Android.Content.PM.ScreenOrientation.Portrait)]
public class MyActivity : Activity 
[...]
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top