Issue
My app needs to instantiate a WebView
that displays the content of a page of a website.
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.
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"
/>
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>
When I access to the same URL with the regular browser, the page does properly fill the screen.
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.
WHAT I HAVE UNSUCCESSFULLY TRIED SO FAR:
- Forcing the LayoutParams
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()
I also looked at this discussion and then tried webview.setScrollBarStyle(WebView.SCROLLBARS_INSIDE_OVERLAY);
, but with no success either.
- Using a LinearLayout
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!
Solution
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" />
Put this piece of code inside the <manifest>
element, just before the <application>
tag in your manifest.
Answered By - Kumar Bibek
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.