简体   繁体   中英

Enable viewport on PhoneGap with Android

PhoneGap : 1.5.0, Android : 2.3.4

I added a viewport tag into my HTML like this:

<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no;">

but it's not working. I have a window with width = 320px, but it should be 480px.

When I Googled this problem, I found this:

Add these 2 line to onCreate() :

this.appView.getSettings().setUseWideViewPort(true);
this.appView.getSettings().setLoadWithOverviewMode(true); 

But after I inserted these two lines I couldn't launch into WebView anymore! Instead, I got the following exception:

ActivityThread.performLaunchActivity(ActivityThread$ActivityRecord, Intent) line: 2496

Here is the exception screenshot

Can anyone help, please?

try this code:

Activity file:

public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
                WindowManager.LayoutParams.FLAG_FULLSCREEN | 
                WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
        super.loadUrl("file:///android_asset/www/index.html");
    }

html file

<meta name="viewport" content="width=device-width,height=device-height,user-scalable=no,target-densitydpi=250,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0" />

with android AndroidManifest.xml android:screenOrientation="landscape" The horizontal display is fullscreen

just tested, preference is not complete solutioin, do following:

config.xml: <preference name="EnableViewportScale" value="true" />

main activity, enable viewport in settings AFTER loadurl:

super.loadUrl(Config.getStartUrl(),1);   
WebSettings settings = appView.getSettings(); 
settings.setUseWideViewPort(true); 
settings.setLoadWithOverviewMode(true); 

I've answered my fix here: https://stackoverflow.com/a/28755743/4612666 Basically change the AndroidManifest.xml min/target version to this:

<uses-sdk android:minSdkVersion="7" />

Can play with the version, not really sure.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM