How to make WebView content appear vertically only? So, as if we turned the phone on the landscape.

I tried to register in .xml WebView - android:screenOrientation="landscape" . Nothing changed.

  • In general, it is not very clear what you mean by "making the contents of the WebView displayed only vertically." Maybe you want different behavior in different screen orientations ... Expand the essence of the question as if you explain it to your cat / five-year-old child. - Yuriy SPb ♦
  • It is necessary for WebView to be displayed as if we took the phone and laid it horizontally, and it automatically turned over (i.e., the width increased the height decreased). - LorDo

2 answers 2

Perhaps you just need to rotate your markup element:

  1. In razmtke:

android:rotation="90.0"

  1. In the code:

webView.setRotation(90.0f);

  • Apparently - no), as you said - the contents of WebView are not displayed correctly, although if you just turn the phone, everything is well displayed. UPD On android version 2.3.4 nothing has changed at all - LorDo
  • @LorDo, what do you mean by "incorrectly"? The fact that the displayed HTML code, with the dimensions of elements specified in pixels, has a "go" layout, doesn’t meet your expectations about how to markup elements, or simply doesn’t display anything at all? Be kind to express yourself very specifically - words like “nothing works” will not help to solve problems to the problem, except with advice like “restart the computer n times” - Yuriy SPb ♦
  • Well, WebView itself turned upside down, but there was no redrawing (re-calculating the height and width), so the content turned out to be outside the screen - LorDo

You can, for example, in the Activity at the right time force the orientation to vertical:

 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); 
  • But it’s like a crutch .... unless it’s different? - LorDo
  • @LorDo, no, no matter how crutch. If you want to do it right , then adapt the contents of the WebView For landscape-orientation. - Vladyslav Matviienko
  • So the content is perfectly oriented, the application itself is made for portrait orientation, and WebView needs to be shown in landscape, and it does not show for a long time, and it turns out that first I change the orientation to landscape by "manual" command, and then back to portrait in a small amount of time, all the same, I think you can set the landscape orientation for WebView separately and not play with these commands. - LorDo