簡體   English   中英

Android:無法實現屏幕方向,應用在設備旋轉時關閉

[英]Android: Unable to achieve screen orientation, app closes on device rotation

旋轉設備后,應用程序即會關閉。 我希望該應用程序在所有四個方向上旋轉。 我在configChanges中包含了screenSize,並將screenOrientation設置為fullSensor。 除了這些包含物之外,我還應該做其他事情來實現屏幕旋轉嗎? AndroidManifest.xml活動代碼如下

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.example.testappone.MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity 
android:name="org.apache.cordova.DroidGap" 
android:label="@string/app_name" 
android:configChanges="orientation|keyboardHidden|screenSize" 
android:screenOrientation="fullSensor">
<intent-filter></intent-filter> </activity> </application>  

 //code for the activity
 <html>
 <head>
 <script type="text/javascript" charset="utf-8" src="cordova.js"></script>
 <link rel="stylesheet" href="css/jquery.mobile-1.2.1.min.css"/>
 <script src="js/jquery-1.6.1.min.js"></script>
 <script src="js/jquery.mobile-1.2.1.min.js"></script>
 <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true"></script>           
 </head>
 <script>
 document.addEventListener("deviceready", onDeviceReady, false);
 function onDeviceReady() {
navigator.geolocation.getCurrentPosition(onSuccess, onError);
 }
function onSuccess(position) {
var lat = position.coords.latitude;
var lon = position.coords.longitude;
initialize(lat, lon);
var lat1=lat; var lon1= lon;
window.lat1 = lat1;
window.lon1 = lon1;
}
function onError(error) {
alert('code: ' + error.code + '\n' +
    'message: ' + error.message + '\n');
}
function Senddata() 
        {
        var Datasend = { "latitude ": lat1,"longitude": lon1   };
             $.post(
                 "http://devtests9.dreamhosters.com/post.php" ,
                {json: JSON.stringify(Datasend)},
                 function (data) {
                     alert("success…" + data);
                 }
             );
         }
 var map;
function initialize(lat, lon) {
var mapDiv = document.getElementById('map-canvas');
if (mapDiv == null) {
    // if not, wait until it does
    google.maps.event.addDomListener(window, 'load', function(){
        initialize(lat, lon);
    });
} else {
map = new google.maps.Map(mapDiv, {
        center: new google.maps.LatLng(lat, lon),
        zoom: 13,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    });
    google.maps.event.addListenerOnce(map, 'tilesloaded', function(){
        addMarkers(lat, lon);
    });
}
}
 function addMarkers(lat, lon) {
var bounds = map.getBounds();
var southWest = bounds.getSouthWest();
var northEast = bounds.getNorthEast();
var lngSpan = northEast.lng() - southWest.lng();
var latSpan = northEast.lat() - southWest.lat();
var latLng = new google.maps.LatLng(lat, lon);
var marker = new google.maps.Marker({
    position: latLng,
    map: map
});
}
  google.maps.event.addDomListener(window, 'load', initialize);
  </script>
      <body style="font-family" style="width:100%; height=500px;">
      <div data-role="page" data-theme="d" id="page1">
      <div data-theme="a" data-role="header" data-position="fixed">
        <h2>
      Map
      </h2>
<a href="#page2" data-icon="arrow-r" data-position="fixed">Post</a>
      </div>
          <div id="map-canvas" style="width:100%; height:500px;"></div>

        <div data-role="footer" data-position="fixed"></div>
        </div>
      <div data-role="page" data-theme="d" id="page2"> 
<div data-role="header" data-position="fixed" >
<a href="#page1" data-icon="arrow-l" data-position="fixed">Map</a>
<h1>Post Location</h1>
</div>
    <button onClick="Senddata();">Tap to Post Location</button>
<div data-role="footer" data-position="fixed">
</div>
</div>
      </body>
      </html>

我一直有同樣的問題。 我的HTML5應用程序無法旋轉。 該應用程序剛剛關閉。

在停止使用PhoneGap 2.9之后,我才能夠做到這一點。 我已經嘗試實現與PhoneGap 2.8.1相同的代碼,但是沒有用。

所以我已經下載了PhoneGao 2.3.0,現在旋轉可以正常工作。

= D

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM