0

In my app I am displaying a webpage that is too big to fit on a portrait display, so I want to rotate it. I tried using RequestedOrientation = ScreenOrientation.Landscape; on the activity but it changes the rotation for the entire phone, rather than just the webview. I also tried making a custom webview class:

 public class VerticalWebView : WebView
    {
        bool topDown = true;

    public VerticalWebView(Context context, IAttributeSet attrs) : base(context, attrs)
        {

        }


        public override void Draw(Canvas canvas)
        {
            if (topDown)
            {
                canvas.Translate(Height, 0);
                canvas.Rotate(90);
            }
            else
            {
                canvas.Translate(0, Width);
                canvas.Rotate(-90);
            }

            canvas.ClipRect(0, 0, Width, Height, Region.Op.Replace);
            base.Draw(canvas);
        }
    }

but i cannot get it to work with the webview XML in the layout file. Any input would be greatly appreciated

Jacob Alley
  • 767
  • 8
  • 34
  • I may be wrong, which is why I am just putting this as a comment, but I don't think you can individually rotate just one thing. I believe you have to rotate the entire display. – gmiley Nov 29 '16 at 19:07
  • i find it hard to believe that would be the case – Jacob Alley Nov 29 '16 at 19:11
  • If you can, maybe provide some mock-up images of what you are trying to achieve. – gmiley Nov 29 '16 at 19:14
  • I cant but it should be pretty self explanatory...i want the webpage to be shown sideways rather than straight up and down. Basically the affect you get when you rotate your phone, and the webpage rotates. I want that. Only with the phone still in an upright position – Jacob Alley Nov 29 '16 at 19:16

1 Answers1

0

correct me if i got your requirement wrong

First direct the orientation of the phone how to detect orientation of android device?

check it and inside the right condition

rotate webView as you want! like below

 WebView webView = (WebView) findViewById(R.id.web);
        webView.loadUrl("https://stackoverflow.com/questions/1930963/rotating-a-view-in-android");
        webView.setRotation(90);

dummy result be like > enter image description here

Community
  • 1
  • 1
Charuක
  • 12,953
  • 5
  • 50
  • 88
  • this is good in theory, but it is not changign the dimensions of the webview. So when you rotate it, I get the same narrow portrait display, just laid on its side. Rather than it filling up the app (like when you actually rotate your phone) – Jacob Alley Nov 29 '16 at 19:24
  • then what about keeping the web view as rotated and change your other views rotation manually(like buttons) ,in the other way around ? – Charuක Nov 29 '16 at 19:33