Android Webview-La página web debe ajustarse a la pantalla del dispositivo
He intentado lo siguiente para ajustar la página web en función del tamaño de la pantalla del dispositivo.
mWebview.setInitialScale(30);
Y luego establecer la ventana de metadatos
<meta name="viewport" content="width=320, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; minimum-scale=1.0; user-scalable=0;"/>
<meta name="viewport" content="width=device-width, target-densityDpi=medium-dpi"/>
Pero nada funciona, la página web no se fija al tamaño de la pantalla del dispositivo.
¿alguien Puede decirme cómo conseguir esto?
19 answers
Tiene que calcular la escala que necesita usar manualmente, en lugar de configurarla en 30.
private int getScale(){
Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
int width = display.getWidth();
Double val = new Double(width)/new Double(PIC_WIDTH);
val = val * 100d;
return val.intValue();
}
Luego use
WebView web = new WebView(this);
web.setPadding(0, 0, 0, 0);
web.setInitialScale(getScale());
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2010-10-12 16:05:34
Puedes usar esto
WebView browser = (WebView) findViewById(R.id.webview);
browser.getSettings().setLoadWithOverviewMode(true);
browser.getSettings().setUseWideViewPort(true);
Esto corrige el tamaño en función del tamaño de la pantalla.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-09-20 05:17:24
Amigos,
He encontrado una gran cantidad de importación y gran información de usted. Pero, la única manera que funciona para mí era de esta manera:
webView = (WebView) findViewById(R.id.noticiasWebView);
webView.setInitialScale(1);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setLoadWithOverviewMode(true);
webView.getSettings().setUseWideViewPort(true);
webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
webView.setScrollbarFadingEnabled(false);
webView.loadUrl("http://www.resource.com.br/");
Estoy trabajando en Android 2.1 debido al tipo de dispositivos de la compañía. Pero arreglé mi problema usando la parte de información de cada uno.
Gracias!
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-06-27 11:09:17
Pruebe con este HTML5 consejos
Http://www.html5rocks.com/en/mobile/mobifying.html
Y con esto si su versión de Android es 2.1 o superior
WebView.getSettings().setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-02-15 00:26:34
Estos ajustes funcionaron para mí:
wv.setInitialScale(1);
wv.getSettings().setLoadWithOverviewMode(true);
wv.getSettings().setUseWideViewPort(true);
wv.getSettings().setJavaScriptEnabled(true);
setInitialScale(1) faltaba en mis intentos.
Aunque la documentación dice que 0 te alejas si setUseWideViewPort es a true pero 0 no me funciona y he tenido que configurar 1.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-10-07 11:14:41
Estos funcionan para mí y ajustan la vista web al ancho de la pantalla:
// get from xml, with all size set "fill_parent"
webView = (WebView) findViewById(R.id.webview_in_layout);
// fit the width of screen
webView.getSettings().setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);
// remove a weird white line on the right size
webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
Gracias arriba aconseja y Línea blanca en eclipse Web view
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-05-23 12:03:02
Todo lo que necesita hacer es simplemente
webView.getSettings().setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);
webView.getSettings().setLoadWithOverviewMode(true);
webView.getSettings().setUseWideViewPort(true);
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-07-17 03:23:46
Tengo el mismo problema cuando uso este código
webview.setWebViewClient(new WebViewClient() {
}
Así puede ser que usted debe eliminar en su código
Y recuerde agregar 3 modos a continuación para su webview
webview.getSettings().setJavaScriptEnabled(true);
webview.getSettings().setLoadWithOverviewMode(true);
webview.getSettings().setUseWideViewPort(true);
Esto corrige el tamaño basado en el tamaño de la pantalla
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-08-06 04:31:28
WebView browser = (WebView) findViewById(R.id.webview);
browser.getSettings().setLoadWithOverviewMode(true);
browser.getSettings().setUseWideViewPort(true);
browser.getSettings().setMinimumFontSize(40);
Esto funciona muy bien para mí, ya que el tamaño del texto se ha establecido en muy pequeño por .setLoadWithOverViewMode y .Usa Wideviewport.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-03-20 12:01:18
Tienes que usar HTML en tu WebView en este caso. Resolví esto usando el siguiente código
webView.loadDataWithBaseURL(null,
"<!DOCTYPE html><html><body style = \"text-align:center\"><img src= "
+ \"http://www.koenvangorp.be/photos/2005_09_16-moon_2000.jpg\"
+ " alt=\"pageNo\" width=\"100%\"></body></html>",
"text/html", "UTF-8", null);
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-01-09 11:30:44
Esto parece un problema XML. Abra el documento XML que contiene la vista web. Eliminar el código de relleno en la parte superior.
Luego , en el diseño, agregue
android:layout_width="fill_parent"
android:layout_height="fill_parent"
En la Vista Web, agregue
android:layout_width="fill_parent"
android:layout_height="fill_parent"
Esto hace que la vista web se ajuste a la pantalla del dispositivo.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-10-19 01:48:30
Realizar cambios en la respuesta de danh32 desde la visualización.getWidth (); ahora está obsoleto.
private int getScale(){
Point p = new Point();
Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
display.getSize(p);
int width = p.x;
Double val = new Double(width)/new Double(PIC_WIDTH);
val = val * 100d;
return val.intValue();
}
Luego use
WebView web = new WebView(this);
web.setPadding(0, 0, 0, 0);
web.setInitialScale(getScale());
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-04-03 20:45:21
int PIC_WIDTH= webView.getRight()-webView.getLeft();
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-10-04 04:32:34
El método getWidth del objeto Display está obsoleto. Sobreescriba onSizeChanged para obtener el tamaño de la vista WEB cuando esté disponible.
WebView webView = new WebView(context) {
@Override
protected void onSizeChanged(int w, int h, int ow, int oh) {
// if width is zero, this method will be called again
if (w != 0) {
Double scale = Double.valueOf(w) / Double.valueOf(WEB_PAGE_WIDTH);
scale *= 100d;
setInitialScale(scale.intValue());
}
super.onSizeChanged(w, h, ow, oh);
}
};
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-02-01 02:29:54
webview.setInitialScale(1);
webview.getSettings().setLoadWithOverviewMode(true);
webview.getSettings().setUseWideViewPort(true);
webview.getSettings().setJavaScriptEnabled(true);
Funcionará, pero recuerde eliminar algo como:
<meta name="viewport" content="user-scalable=no"/>
Si existe en el archivo html o cambia user-scalable = yes, de lo contrario no lo hará.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-10-18 09:56:53
Tenía video en cadena html, y el ancho de la vista web era más grande que el ancho de la pantalla y esto está funcionando para mí.
Agregue estas líneas a la cadena HTML.
<head>
<meta name="viewport" content="width=device-width">
</head>
Resultado después de agregar el código anterior a la cadena HTML:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width">
</head>
</html>
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-04-05 09:41:47
Esto ayudará a ajustar el emulador de acuerdo con la página web:
WebView wb;
//CALL THIS METHOD
wb.setInitialScale(50);
Puede establecer la escala inicial en porcentaje como se muestra arriba.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-12-07 10:26:24
En teoría la combinación de:
settings.setLayoutAlgorithm(LayoutAlgorithm.NARROW_COLUMNS);
Con
settings.setUseWideViewPort(false)
Soluciona el problema, envolviendo el contenido y ajustándolo a la pantalla. Pero el NARROW_COLUMNS ha sido obsoleta. Te aconsejo que leas este hilo a continuación que explora el tema en detalle: https://code.google.com/p/android/issues/detail?id=62378
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-06-03 22:37:58
WebView webView = (WebView)findViewById(R.id.web_view);
webView.setInitialScale((int) getResources().getDimension(R.dimen._50sdp)); // getActivity(). if you are at Fragment
webView.getSettings().setLoadsImagesAutomatically(true);
webView.getSettings().setJavaScriptEnabled(true);
webView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
webView.loadDataWithBaseURL(null,here comes html content,"text/html","UTF-8", null);
webView.getSettings().setBuiltInZoomControls(true);
webView.getSettings().setSupportZoom(true);
webView.getSettings().setDisplayZoomControls(true);
webView.getSettings().setDefaultZoom(WebSettings.ZoomDensity.FAR);
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-12-25 16:27:13