简体   繁体   English

如何为小屏幕和大屏幕设置相同的Webview宽度

[英]How to set webview width the same for small screen and large screens

In my app i make use of webview. 在我的应用程序中,我使用了webview。 The webviews are taking the sizes of the images that i load into them. Webview正在获取我加载到其中的图像的大小。 Now is the problem that if i want to view them on a 7" or 10" tablet screen i'm getting a white border on the right side of the webview. 现在的问题是,如果我想在7“或10”平板电脑屏幕上查看它们,则Webview的右侧会出现白色边框。

So i want that the images fit into the webviews on small and large screens. 所以我希望图像适合小屏幕和大屏幕上的webview。

This is the code for a webview that i have: 这是我有一个webview的代码:

package be.weaterApp.weatherwatch;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class Dauwpunten extends Activity{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.temperaturen);

    String loadUrl = "http://www.meteociel.fr/cartes_obs/pointrosee.png";

    // initialize the browser object
    WebView browser = (WebView) findViewById(R.id.webviewt);

    browser.getSettings().setLoadWithOverviewMode(true);
    browser.getSettings().setUseWideViewPort(true);
    browser.getSettings().setBuiltInZoomControls(true);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    final ProgressDialog pd = ProgressDialog.show(this, "", "De kaart wordt geladen...", true);
    //setContentView(R.layout.weerforu);

    browser.setWebViewClient(new WebViewClient() {
      @Override
      public void onPageFinished(WebView view, String url) {
        pd.dismiss();
      }
    });
    try {
        // load the url
        browser.loadUrl(loadUrl);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
}

And this is for the xml: 这是针对xml的:

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






<com.android.sdk.mobgold.MobRequest
    android:id="@+id/ad"
    android:layout_width="fill_parent"
    android:layout_height="50dip"
    android:layout_gravity="center_horizontal"
    android:clickable="true" />


<android.webkit.WebView
    android:id="@+id/webviewt"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

</android.webkit.WebView>

</LinearLayout>

我会将PNG包装在一个小的HTML文件中,并将其图片标签设置为100%宽度。

If you create a webview whose size is set to the size of an image, the webview is going to be different sizes on different resolution devices. 如果创建的Web视图的大小设置为图像的大小,则在不同分辨率的设备上Web视图的大小将不同。 A better way to do it (if you want your app to appear the same on all screen sizes) would be to use weights ( android:layout_weight="X" ) to create a proportional layout which doesn't depend on the size of the content, but makes the webview take up a certain percentage of the screen instead. 更好的方法(如果您希望您的应用在所有屏幕尺寸上都显示相同)将使用权重( android:layout_weight="X" )创建不依赖于屏幕尺寸的比例布局内容,但使Webview占据了屏幕的特定百分比。 This way, you can make your webview (for example) take up exactly 50% of the screen regardless of the size of the device. 这样,无论设备的大小如何,您都可以使Web视图(例如)恰好占据屏幕的50%。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 应用程序在小屏幕上崩溃,但不在大屏幕上崩溃 - Application crashes on small screen but not in large screens 多屏幕支持大屏幕和小屏幕 - Multiple screen support for large and small screens 如何确定设备屏幕尺寸类别(小,常规,大,xlarge)以测试应用程序中的不同屏幕? - How to determine device screen size category (small, normal, large, xlarge) in order to test different screens in an application? 猕猴桃中的屏幕支持设置为普通和大屏幕 - screen support in kivy set to normal and large screens Android webview设置的宽度不超过屏幕宽度 - Android webview set width not taken more than screen width 如何设置布局宽度以在不同屏幕尺寸下查看相同 - How to set layout width to view the same in different screen sizes 如何将RelativeLayout的宽度设置为屏幕宽度? - How I set the width of RelativeLayout to screen width? 如何设置 webview 的初始缩放/宽度 - How to set the initial zoom/width for a webview 如何使大屏幕和大屏幕的布局保持一致?总会有一些空白 - How to make layout consistent for small and large screens ?There's is always some whitespace left Android在大屏幕底部设置了一个ImageView,小屏幕则滚动了它 - Android set an ImageView at the bottom with big screens and Scroll it with Small Screens
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM