[英]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.