4

我正在尝试获取标题“54dp”,其余的活动是 WebView。

当我在 eclips 的“图形布局”中预览我的活动时,它看起来不错。但是当在手机或模拟器上运行应用程序时,webview 会占据整个屏幕。

这就是预览的样子和我想要的样子:

在此处输入图像描述

但这是我在运行应用程序时看到的:

在此处输入图像描述

这是布局 xml 的样子:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/page_background"
    >

    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/Layout_Header"
        android:layout_width="fill_parent"
        android:layout_height="54dp"
        android:orientation="horizontal" 
        android:background="@drawable/container_header"
        android:paddingLeft="16dp"
        android:paddingRight="16dp"

        >

        <ImageView
            android:id="@+id/imgHeaderLogo"
            android:layout_weight="1"
            android:layout_width="0dp"
            android:layout_height="46dp"
            android:contentDescription="@string/img_header_logo_description"
            android:src="@drawable/header_logo" 
            android:layout_gravity="center"
            />


    </LinearLayout>


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

解决方案:

在活动java文件中我有这个:

WebView browser = (WebView) findViewById(R.id.web_engine);
WebSettings webSettings = browser.getSettings();
setContentView(browser);

当我应该有这个时:

setContentView(R.layout.activity_sign_in_web_view);
4

3 回答 3

4

这是因为一些重定向,打开浏览器应用程序,你可以使用

webview.setWebViewClient(new WebViewClient() {
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {         
        view.loadUrl(url);
        return true;
    }
});

在您的WebView. 我刚刚遇到了同样的问题,在这里找到了解决方案。

于 2013-04-20T17:08:04.500 回答
3

将 WebView 的高度设置为 0dp,将其权重设置为 1。

<WebView android:id="@+id/web_engine"
         android:layout_width="fill_parent"
         android:layout_height="0dp"
         android:layout_weight="1"
        />
于 2013-02-20T03:10:13.543 回答
1

为 web 视图在 xml 中手动更改

android:layout_height="fill_parent"

作为

    android:layout_height="200dp"

如果它有效,可以在“android:layout_height”中根据需要更改高度参数

于 2013-02-20T03:05:26.367 回答