簡體   English   中英

android webview占據全屏

[英]android webview taking up full screen

我正在嘗試獲取標題“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);

這是因為一些重定向,它可以打開瀏覽器應用程序

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

WebView加載重定向。 我剛剛遇到了同樣的問題並在此處找到了解決方案。

將WebView的高度設置為0dp,將其權重設置為1。

<WebView android:id="@+id/web_engine"
         android:layout_width="fill_parent"
         android:layout_height="0dp"
         android:layout_weight="1"
        />

在xml中手動更改此視圖以進行Web視圖

android:layout_height="fill_parent"

    android:layout_height="200dp"

如果它的工作原理,你可以在“android:layout_height”中更改height參數

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM