Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/206.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 边界';WebView中的大小呈现方式不同_Android_Webview_Android Webview - Fatal编程技术网

Android 边界';WebView中的大小呈现方式不同

Android 边界';WebView中的大小呈现方式不同,android,webview,android-webview,Android,Webview,Android Webview,我有一个移动网页,我正在用WebView查看,但由于某些原因,它呈现的边界不同-1px或2px厚。有人经历过吗 下面的示例图片显示了如何使用1px top和2px bottom渲染具有1px top和1px bottom边框的div。这个问题也发生在其他地方,这使得设计看起来很便宜 有什么建议吗 一些代码 活动 import android.app.Activity; import android.os.Bundle; import android.view.Window; import an

我有一个移动网页,我正在用WebView查看,但由于某些原因,它呈现的边界不同-1px或2px厚。有人经历过吗

下面的示例图片显示了如何使用1px top和2px bottom渲染具有1px top和1px bottom边框的div。这个问题也发生在其他地方,这使得设计看起来很便宜

有什么建议吗

一些代码

活动

import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;


public class MainActivity extends Activity {


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_main);
        deleteDatabase("webview.db");
        deleteDatabase("webviewCache.db");
        WebView mywebview = (WebView) findViewById(R.id.webview);

         mywebview.loadUrl("http://example.mobi/");
         WebSettings webSettings = mywebview.getSettings();
         webSettings.setJavaScriptEnabled(true);
         //webSettings.setBuiltInZoomControls(true);
         mywebview.setWebViewClient(new WebViewClient());

    }

}
XML

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    tools:context=".MainActivity" >

    <WebView android:id="@+id/webview" 
         android:layout_width="fill_parent" 
         android:layout_height="fill_parent"
         />

</RelativeLayout>
...
 <meta name="viewport" content="target-densitydpi=device-dpi; width=device-width; initial-scale=1; minimum-scale=1; maximum-scale=1; user-scalable=0;">
<div id="mobilesStatusSubmit">
   post status
</div>
....
电话

星系S2

你试过这个吗

import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;


public class MainActivity extends Activity {


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_main);
        deleteDatabase("webview.db");
        deleteDatabase("webviewCache.db");
        WebView mywebview = (WebView) findViewById(R.id.webview);
       mywebview .setKeepScreenOn(true);
            mywebview .getSettings().setJavaScriptEnabled(true);
             mywebview .getSettings().setDomStorageEnabled(true);
             mywebview .getSettings().setBuiltInZoomControls(true);
             mywebview .setInitialScale(100);
            mywebview .getSettings().setUseWideViewPort(true);
             mywebview .setWebViewClient(new MyWebViewClient());
              mywebview .setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
            mywebview.loadUrl("http://example.mobi/");
           WebSettings webSettings = mywebview.getSettings();
           webSettings.setJavaScriptEnabled(true);
         //webSettings.setBuiltInZoomControls(true);
         mywebview.setWebViewClient(new WebViewClient());

    }

我已经找到了这个问题的解决方案,在下面的教程中有很好的解释

显然,屏幕密度会影响边界,因为我的星系S2的密度约为1.5像素,所以在一些边界中1px变为2(可能有一半的时间)


希望这对其他人有所帮助。

附上您正在使用的屏幕和您的要求图片来自我正在通过WebView查看的网页。它是用html/css设计的,在普通浏览器上,两个边框看起来都很好,厚1倍,但在WebView中,它显示了一些更厚的边框。我已经检查了我的html元标记,它应该是正确的
targetdensitydpi=devicedpi;宽度=设备宽度;初始刻度=1;最小刻度=1;最大刻度=1;用户可伸缩=0在浏览器和移动网络视图中,页面可能是相同的,但您的完整代码将附带一点差异。我将尝试帮助您或网站本身。我已在问题中添加了代码,使其更清晰。我正在Galaxy S2Janmejoy上查看应用程序,我将此代码放在哪里?我对它做了一点修改,因为它会给我错误<代码>WebView web=(WebView)findviewbyd(R.id.WebView)。老实说,我不太懂这门语言。我只想做一个我的网站的快速版本。你能解释一下我该把代码放在哪里吗。到目前为止,我试图把它放在
mywebview.loadUrl
之前和之后,但什么也没发生。感谢您在这方面的帮助。感谢我不得不更改
mywebview.setWebViewClient(新的MyWebViewClient())
to
mywebview.setWebViewClient(新的WebViewClient())以使其工作,但页面看起来相同:(顶部边框更厚。此解决方案使边框在css中不存在,并使用框阴影属性创建边框。无论如何,此解决方案有效,并提供了即时解决方案。+1“404我们找不到此页面。”您能否解释或添加一些代码示例@Ando?提前感谢。
import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;


public class MainActivity extends Activity {


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_main);
        deleteDatabase("webview.db");
        deleteDatabase("webviewCache.db");
        WebView mywebview = (WebView) findViewById(R.id.webview);
       mywebview .setKeepScreenOn(true);
            mywebview .getSettings().setJavaScriptEnabled(true);
             mywebview .getSettings().setDomStorageEnabled(true);
             mywebview .getSettings().setBuiltInZoomControls(true);
             mywebview .setInitialScale(100);
            mywebview .getSettings().setUseWideViewPort(true);
             mywebview .setWebViewClient(new MyWebViewClient());
              mywebview .setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
            mywebview.loadUrl("http://example.mobi/");
           WebSettings webSettings = mywebview.getSettings();
           webSettings.setJavaScriptEnabled(true);
         //webSettings.setBuiltInZoomControls(true);
         mywebview.setWebViewClient(new WebViewClient());

    }