Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pinch Zoom in Android with Phonegap and jQUERY Mobile

I have been having difficult getting pinch zoom to work in the webapp I am creating with Phonegap. Currently, I am loading information into a p tag view a remote script, but the html goes out of the confines of the screen (of course going to landscape mode fixes this).

Not matter, what I try I can't get pinch zoom to work or even a horizantal scrollbar to appear. I tried adding <meta name="viewport" content="width=device-width, height=device-height, initial-scale=0.8, user-scalable=1" /> in the header.

I think the problem may be that I am using jquery mobile, but trying the following solution did not work either:

$(document).bind("mobileinit", function(){
      $.mobile.metaViewportContent = "width=device-width, minimum-scale=1, maximum-scale=2";
});

(added before jquery mobile js file inclusions).

EDIT: Scrolling to the right when content overflows works fine in Ripple emulator.


UPDATE: Okay - edited my app.java and I am able to zoom now. However, I am only able to zoom in, not zoom out, indicating that the initial zoom is set to 1 I guess. Anyone have any suggestions as to how to zoom out or set up a horizontal scroll bar?

package com.phonegap.Sample;

import android.app.Activity;
import android.os.Bundle;
import com.phonegap.*;
import android.webkit.WebSettings;

public class Sample extends DroidGap
{
@Override
public void onCreate(Bundle savedInstanceState)
{


    super.onCreate(savedInstanceState);
    super.loadUrl("file:///android_asset/www/index.html");

    WebSettings ws = super.appView.getSettings();
    ws.setSupportZoom(true);
    ws.setBuiltInZoomControls(true); 

}
}

source

like image 582
John Smith Avatar asked May 15 '11 05:05

John Smith


1 Answers

I realize this post is old, but here's to anyone else googling their way into the post:

Horizontal zoom is actually not available for any content except within the body - for both iOS and and Android to my knowledge. Try creating a new app with a div and try to make overflow:auto give you anything. There's ScrollView being implemented into jQuery Mobile, and there's iScroll. Neither works well if u want form elements to be within the scrollable area.

As to zooming out farther than the actual content, I don't think it's unreasonable it actually locks you in. There's nothing outside the body which can be showed, imagine how a background color or image would be clipped - not nice at all!

like image 51
Zut Avatar answered Oct 14 '22 04:10

Zut