简体   繁体   中英

android webview taking up full screen

I'm trying to get a header "54dp" and a the rest of the activity be a WebView.

When I preview my activy in the "Graphical Layout" within eclips it looks good. But when run the application on the phone or emulator the webview takes up the entire screen.

This is what the preview looks like and how I want it:

在此输入图像描述

But this is what I see when I run the app:

在此输入图像描述

This is what the layout xml looks like:

<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>

SOLUTION:

in the activity java file I had this:

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

When I should have had this:

setContentView(R.layout.activity_sign_in_web_view);

This is because of some redirect, which open the Browser application, you can use

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

to load the redirection in your WebView . I've just had the same issue and found the solution here .

Set the WebView's height to 0dp and its weight to 1.

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

change this manually in xml for web view

android:layout_height="fill_parent"

as

    android:layout_height="200dp"

And if it works change the height parameter as you like in the "android:layout_height"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM