escalando webview a toda la pantalla en android

I am trying to scale the webview to the size of the screen , but I have failed at it .. I have tried lots of combinations but none of them worked for me .What am I missing in that code ? Any help is greatly appreciated.

package com.example.images;

import android.app.Activity; 
import android.os.Bundle; 
import android.webkit.WebView; 

public class MainActivity extends Activity { 

private WebView webView; 
@Override 
public void onCreate(Bundle savedInstanceState) { 
   super.onCreate(savedInstanceState); 
   setContentView(R.layout.main); 
  webView  = (WebView) findViewById(R.id.webview_compontent); 


  String r="<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0,target-densityDpi=device-dpi\">"; 

        String s="<html><head>"+"<style>body{margin:0; }</style>" +r+"</head>" +"<body>"+
           "<IMG src="+ "\"http://46.20.150.55/member/Resimler/kampanya/195/314/blackmakas1.jpg\">" +
           "<DIV style=\"Z-INDEX: 1; POSITION: absolute; TEXT-ALIGN: center; BACKGROUND-COLOR: white;" +
           "WIDTH: 80px; TOP: 137px; LEFT: 121px\">564524</DIV>"+"</body><html>"; 

   webView.setBackgroundColor(0); 
   webView.setBackgroundResource(R.drawable.android); 
   webView.loadData(s, "text/html","UTF-8");  



  //doesn't work
  /*webView.getSettings().setLoadWithOverviewMode(true); 
   webView.getSettings().setUseWideViewPort(true); 

   try { 
       // load the url 
       webView.loadData(s, "text/html","UTF-8");
   } catch (Exception e) { 
       e.printStackTrace(); 
   } */

   //doesn't work

 /* webView.setInitialScale(1); 
  webView.getSettings().setLoadWithOverviewMode(true); 
  webView.getSettings().setUseWideViewPort(true); 
  webView.getSettings().setJavaScriptEnabled(true); 
  */

  //doesn't work

  /* String p="<html><head>"+"<style>body{margin:0; }</style>" +r+"</head>" +"<body>"+
           "<IMG src="+ "\"http://46.20.150.55/member/Resimler/kampanya/195/314/blackmakas1.jpg\">" +
           "<DIV style=\"Z-INDEX: 1; POSITION: absolute; TEXT-ALIGN: center; BACKGROUND-COLOR: white;" +
           "WIDTH: 80px; TOP: 137px; LEFT: 121px\">564524</DIV>"+"</body><html>"; 

   webView.loadData(p, "text/html","UTF-8");

   webView.getSettings().setJavaScriptEnabled(true); 
   webView.getSettings().setLoadWithOverviewMode(true); 
   webView.getSettings().setUseWideViewPort(true); 
   webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY); 
   webView.setScrollbarFadingEnabled(false);   */   

  } } 

Aquí está principal.xml

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

  >


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

 />


 </LinearLayout>

And here is manifest file

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.images"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="15" />

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".MainActivity"
        android:label="@string/title_activity_main" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

(Editted)

The webpage I get is :

This is the page that I get .. What I want is to fit that advertisement image to all the screen.

enter image description here

preguntado el 31 de julio de 12 a las 15:07

Please show main layout xml. BTW there is a chance you're using wrong layout params (i.e. wrap_content instead of match_parent). -

editted right now, i have tried many things but nothing else worked:( where am i making mistake ? -

Well I think that should work too but please try with relative layout and match_parent since fill_parent is obsolete. -

I have just did what you said , but didn't work .. -

2 Respuestas

The problem is your webwiew is fullscreen but blackmakas is not. webView.setBackgroundResource(R.drawable.android); this line shows that you have the fullscreen. The problem is in your html.

Respondido 01 ago 12, 08:08

thank you , i have tried it but now i get "the application has stopped unexpectedly" error.. - asdfg

Please place it right after super.onCreate(savedInstanceState); - Atún Karakasoglu

I have tried it but it couldn't get it worked , it just removes the status bar above , the size of the webview still does not fit the screen , it is still small - asdfg

Can you please post a screenshot. Then we can see it. - Atún Karakasoglu

I have uploaded the image just now ,the thing I want is to fit the image on the left handside to all the screen . - asdfg

I think you need to use a WEbViewClient to load the url into a full screen image because the problem you are facing is that you are trying to load the webview with a width and height before the view is actually set .

Try following the tutorials here at : http://www.technotalkative.com/android-webviewclient-example/ y éste : http://www.chrisdanielson.com/tag/webviewclient/

Respondido 31 Jul 12, 18:07

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.