Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/81.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不像浏览器那样呈现css?_Android_Html_Css_Android Webview - Fatal编程技术网

Android WebView不像浏览器那样呈现css?

Android WebView不像浏览器那样呈现css?,android,html,css,android-webview,Android,Html,Css,Android Webview,就我所知,WebView和内置浏览器是一样的吗?对吧? 我面临的问题是,包含一些绝对定位的div元素的页面都堆叠在彼此的顶部,而没有找到它们的正确位置,并且背景图像被完全忽略 这就是说,在我手机的浏览器中(HTC难以置信的S-2.3.3,股票浏览器)正确地呈现了它,最重要的是,使用嵌入式webview的应用程序,我可以将它指向页面,正确地呈现了它。这让我觉得我的应用程序中的webview在某种程度上正在运行 import android.app.Activity; import android.

就我所知,WebView和内置浏览器是一样的吗?对吧?

我面临的问题是,包含一些绝对定位的div元素的页面都堆叠在彼此的顶部,而没有找到它们的正确位置,并且背景图像被完全忽略

这就是说,在我手机的浏览器中(HTC难以置信的S-2.3.3,股票浏览器)正确地呈现了它,最重要的是,使用嵌入式webview的应用程序,我可以将它指向页面,正确地呈现了它。这让我觉得我的应用程序中的webview在某种程度上正在运行

import android.app.Activity;
import android.content.Intent;
import android.graphics.Rect;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebSettings.LayoutAlgorithm;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.Toast;

import java.util.*;

public class ShowWebView extends Activity {

    public WebView web;
    public String baseURL = "http://test.dev/";

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.webpage);

        web = (WebView) findViewById(R.id.webpage);
        home = (Button) findViewById(R.id.tool_Home);
        back = (ImageButton) findViewById(R.id.tool_Back);
        forward = (ImageButton) findViewById(R.id.tool_Forward);
        refresh = (ImageButton) findViewById(R.id.tool_Refresh);

        ajax = (ImageView) findViewById(R.id.test_anim);
        ajax.setBackgroundResource(R.drawable.ajax_animation);


        // Settings
        web.getSettings().setJavaScriptEnabled(true);
        web.getSettings().setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);
        web.setWebViewClient(new WebViewClient());

        Bundle extras = getIntent().getExtras();
        if(extras != null) {

            String url = baseURL+extras.getString("page")+"?androidApplication"; // The Basics, page gets added to baseURL
            String id = "";
            String push = "false"; // false by default

            // If an ID exists, lets get it
            if(extras.getString("id") != null) {
                id = extras.getString("id");
            }

            if(extras.getString("push") != null) {
                push = extras.getString("push");
            }

            // Build the URL
            if(id != "") url = url + "&id="+id;
            if(push != "false")     url = url + "&pushVersion";

            web.loadUrl(url);
        } else {
            web.loadUrl("http://www.bing.com");
        }
}
这里还有我的webview xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    style="@style/MainPage"
    android:orientation="vertical" >

    <LinearLayout
        android:id="@+id/Header"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >


        <ImageView
            android:id="@+id/ImageView01"
            android:layout_width="match_parent"
            android:layout_height="42sp"
            android:scaleType="fitXY"
            android:src="@drawable/top_header" />

    </LinearLayout>
    <LinearLayout
        android:id="@+id/SubHeader"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >


        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="match_parent"
            android:layout_height="28sp"
            android:scaleType="fitXY"
            android:src="@drawable/top_sub_header" />

    </LinearLayout>

    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >








        <LinearLayout
            android:id="@+id/linearLayout2"
            android:layout_width="match_parent"
            android:layout_height="0dip"
            android:layout_weight="1"
            android:orientation="vertical" >

            <WebView
                xmlns:android="http://schemas.android.com/apk/res/android"
                android:id="@+id/webpage"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                 />

        </LinearLayout>




        <LinearLayout
            android:id="@+id/toolBar"
            android:layout_width="match_parent"
            android:layout_height="40sp"
            android:layout_marginTop="2.5sp"
            android:orientation="horizontal" >

            <Button
                android:id="@+id/tool_Home"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Home" />


            <ImageButton
                android:id="@+id/tool_Back"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/backward" />


            <ImageButton
                android:id="@+id/tool_Forward"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/forward" />


            <ImageButton
                android:id="@+id/tool_Refresh"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/refresh" />


            <ImageView
                android:id="@+id/test_anim"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:layout_centerHorizontal="true" />

        </LinearLayout>

    </LinearLayout>

</LinearLayout>

任何有助于解决这个问题的帮助都将是非常了不起的

显然:

web.getSettings().setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);
导致webview崩溃,因为它重新组织html呈现程序,将所有内容都放在一列中(或者尝试以任何方式)。禁用该行或使用窄列将导致渲染效果良好


我只是用这一行来禁用水平滚动。因此,现在我仍然要处理这个问题。

我可以提出一些解决问题的想法,以帮助获得更多信息。1.)当您说它在您手机的浏览器上正确呈现时,只是为了确定,这部手机是否与您运行应用程序的位置相同?不同版本的Android对CSS的支持不同。2.)如果删除所有视图,并且布局中只有一个WebView,它会改变什么吗?3.)如果您在WebView中打开其他具有背景位置和绝对位置的网站(可能是具有html/css示例的网站),是否存在相同的问题,或者只是您的html/css?我感谢您的输入,因为它引导我走上了正确的道路!我知道发生了什么,请查看我上面的问题(在最上面)以获得答案:)谢谢。帮了我很多忙。setLayoutAlgorithm(LayoutAlgorithm.NORMAL)帮了我一把。你应该把你找到的答案作为下面的答案插入(然后接受),而不是对你的问题进行编辑。尝试了所有方法,这最终对我有效。如果你对CSS有问题,试试这个。谢谢是的,这一行修复了CSS呈现问题:
web.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.窄列),+1表示答案