我的WebView没有填满标签“屏幕(但充满了手机的屏幕没有PB) [英] My WebView does not fill the tabs' screens (but fills the cellphones' screens with no pb)
问题描述
我的应用程序需要实例的WebView
显示一个网站的页面内容。
My app needs to instantiate a WebView
that displays the content of a page of a website.
它与手机完美的作品(我试过各种HTC的和最近的三星太),但它不与片(Galaxy Tab的,或者华硕Eee Pad的变压器):不是填充屏幕的的WebView
出现非常小。
It works perfectly with cellphones (I've tried with various HTC's and with a recent Samsung too) but it doesn't with tablets (Galaxy Tab, or Asus Eee Pad Transformer) : instead of filling the screen the WebView
appears very small.
根据不同的标签,视区的大约25%至50%的填充,其余为空。它看起来有点好像我是用 WRAP_CONTENT
而不是 FILL_PARENT
。
Depending of the tabs, roughly 25% to 50% of the viewport is filled, the rest is blank. It looks a bit as if I was using WRAP_CONTENT
instead of FILL_PARENT
.
布局我使用看起来像这样:
The layout I'm using looks like this:
<?xml version="1.0" encoding="utf-8"?>
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
的的onCreate()
使用此布局的活动是这样的:
The onCreate()
of the activity that uses this layout looks like this:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.showdoc); // showdoc is the layout above
// Configuration of the WebView
final WebView webview = (WebView) findViewById(R.id.webview);
final WebSettings settings = webview.getSettings();
settings.setJavaScriptEnabled(true);
// Callbacks setup
final Context ctx = this;
webview.setWebViewClient(new WebViewClient() {
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
Toast.makeText(ctx, getResources().getString(R.string.error_web) + description, Toast.LENGTH_LONG).show();
}
});
// Display of the page
webview.loadUrl(getResources().getString(R.string.doc_url) + Locale.getDefault().toString());
}
和清单文件看起来是这样的:
And the manifest file looks like this:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapp"
android:versionCode="1"
android:versionName="1.0">
<uses-permission android:name="android.permission.INTERNET" />
<application android:icon="@drawable/icon"
android:label="@string/app_name"
android:debuggable="true">
<activity android:name=".MainActivity"
android:label="@string/app_name"
android:configChanges="keyboardHidden|orientation">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="3" />
</manifest>
当我访问相同的URL与普通的浏览器,页面不正确地填满屏幕。
When I access to the same URL with the regular browser, the page does properly fill the screen.
下面的截图中执政。仿真器使用的是三星Galaxy Tab 10条作出,但结果基本上是一个物理的Eee Pad的变压器,在的WebView
为50%,同小。在手机上,没问题,的WebView
采取所有可用的空间。
The screenshot below were made using a Samsung Galaxy Tab 10 in. emulator, but the result is basically the same on a physical Eee Pad Transformer, the WebView
being 50% smaller. On a cellphone, no problem, the WebView
takes all the available room.
我的应用程序,在横向模式下:
My app, in landscape mode:
我的应用程序,在纵向模式下:
My app, in portrait mode:
同样的网址,相同的硬件,用默认的浏览器,在横向模式下:
Same URL, same hardware, with the default browser, in landscape mode:
同样的网址,相同的硬件,默认浏览器,在人像模式:
Same URL, same hardware, with the default browser, in portrait mode:
因此,它必须是一个设置事
So it must be a matter of settings.
我有什么不成功地设法至今:
- 强制的LayoutParams
我最初以为这是一个的LayoutParams
的问题,所以我尝试添加接下来我的的onCreate()
,但没有成功。它只是不会改变任何东西:
I initially thought it was a LayoutParams
problem, so I tried adding what follows to my onCreate()
, but with no success. It just doesn't change anything:
// Zoom out
final Display display = getWindowManager().getDefaultDisplay();
final int width = display.getWidth();
final int height = display.getHeight();
webview.setLayoutParams(new LayoutParams(width, height));
- setScrollBarStyle()
- 使用的LinearLayout
我也看了<一个href=\"http://stackoverflow.com/questions/3859502/why-isnt-my-webview-filling-up-the-entire-width-of-my-screen\">this讨论然后试图 webview.setScrollBarStyle(WebView.SCROLLBARS_INSIDE_OVERLAY);
,但没有成功或者
I also looked at this discussion and then tried webview.setScrollBarStyle(WebView.SCROLLBARS_INSIDE_OVERLAY);
, but with no success either.
我试图改变在布局
进一步如下您的反馈意见(见下文),但它不会改变任何东西:
I have tried changing the Layout
as follows further to your feedback (see below), but it does not change anything:
<?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">
<WebView
android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</LinearLayout>
你有什么想法?
在此先感谢!
Do you have any idea? Thanks in advance!
推荐答案
我的猜测是,它是在平板电脑兼容模式下运行。检查清单文件。你可以发布你所看到的截图?
My guess is that it is running in compatibility mode for tablets. Check your manifest file. Could you post a screenshot of what you are seeing?
我的怀疑是正确的。它在兼容模式下运行。
My suspicion was correct. It is running in compatibility mode.
<supports-screens android:largeScreens="true"
android:normalScreens="true" android:smallScreens="true"
android:anyDensity="true" android:xlargeScreens="false" />
把这块&LT内部code的;清单&GT;
元素,之前在&lt;应用&GT; $ C $在清单C>标记。
这篇关于我的WebView没有填满标签“屏幕(但充满了手机的屏幕没有PB)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!