Several methods to solve the problem that PhoneGap does not support viewport

  • 2021-10-25 07:52:29
  • OfStack

When compiling GameBuilder+CanTK with phonegap a few days ago, it was found that viewport in HTML was invalid. CanTK detects the device's DPI against devicePixelRatio, and then sets the correct resolution with viewport. If viewport is invalid, CanTK can only run at the lowest resolution. I checked on the Internet for 1 time, but I didn't find the data of the system, but I know that WebView1 has corresponding settings to enable viewport. Combined with the data found and the source code of phonegap, I finally found a solution. Summarize 1 time here:

Solution of iOS platform: Add 1 line configuration in config. xml of phonegap:

<preference name="EnableViewportScale" value="true"/>

(Strangely, this method doesn't work on the android platform. I looked at CordovaWebView. java, and there is no relevant setting in it.)

Solution 1 for the android platform: Modify CordovaWebView. java:


  settings.getUserAgentString();
   // Add the following two lines of code: 
  settings.setUseWideViewPort(true);
  settings.setLoadWithOverviewMode(true);

Solution 2 of android platform: It is a good way to modify CordovaWebView. java directly, but GameBuilder+CanTK supports cloud compilation of phonegap, so there is no way to modify CordovaWebView. java directly. I thought of phonegap plug-in, found an ViewPortScale plug-in, and found that it couldn't be compiled at all, so I wrote an com. tangide. viewport plug-in. If I use the cloud compilation provided by GameBuilder + CanTK, I have built-in this plug-in. The source code for the plug-in is here:

https://github.com/drawapp8/ViewPort

Summarize


Related articles: