1
<script>
document.addEventListener("orientationChanged", updateOrientation);

 function updateOrientation(e) {
    switch (e.orientation)
    {   
        case 0:
            // Do your thing
            break;

        case -90:
            var ele=document.getElementById("photoBox")
            ele.width='200px';
            ele.height='200px';
            ele.style.float='center';
            break;

        case 90:
             var ele=document.getElementById("photoBox")
                ele.width='200px';
                ele.height='200px';
                ele.style.float='center';
                break;
        default:
            break;
        }
    } 
</script>

I have used this is code for the Gallery in my application. The problem that i am facing is, whenever I change the orientation of the device, the images disappear. I do not get any error message in the logcat.

I am very specific about the code being in javascript. Inspite of me using it for android, i cant make any changes on the native side.

Any help is appreciated. Thanks.

Hurda
  • 4,647
  • 8
  • 35
  • 49
Khush
  • 867
  • 1
  • 19
  • 46

1 Answers1

0

you can do this by adding "configChanges" attribute in your activity in AndroidManifest.xml as follows

<activity
        android:configChanges="orientation|keyboard"
        android:name=".MyActivity">
 </activity>

and in your activity(MyActivity.java) please override the method "onConfigurationChanged(Configuration configuration)" as follows

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
}

This should solve your problem

silwar
  • 6,470
  • 3
  • 46
  • 66
  • nothing changed. I have using a js file to swipe through the images. probably that is controlling everything and its not loadin the images during orientation. – Khush Jan 21 '12 at 10:18
  • have u checked this [this](http://stackoverflow.com/questions/1649086/detect-rotation-of-android-phone-in-the-browser-with-javascript) – silwar Jan 21 '12 at 11:10
  • This override is total bulshit, it does nothing. just launches parent taht woudl be launched anyway... – Hurda Jan 21 '12 at 16:23