Hi, it's my first time writing here and I want giving thanks everybody
who makes the group possible. Specially to all the Android
developpers. Well, let's go to the problem: I'm trying to rotate a
WebView according with the orientation sensor. That's because below
this view I have a GLSurfaceView wich I don't want to rotate, so as
probably you'd have suppossed I set orientation in landscape mode,
avoiding the automatic rotate of the cell.

To achieve my goal I include the class WebView in another one using
composition. This class is named, in example, ExtWebView and overrides
the onDraw method with canvas.rotate(-90) (after a translate). The
class ExtWebView extends the LinearLayout one. The problems begins
when I decide set the WebView in a non square portion of the screen
(not the whole one). So I add the WebView to the ExtWebView with
"addView(WebView, 200, 300);". In the main Activity I add the
ExtWebView with "addContentView(ExtWebView, new
LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));" so
it should being able to use the whole screen.

And now come the problem. The rotated WebView appears initially fine
(rotated like expected), but if I slide my finger on it left or right
(coords are changed and works like up and down, but that doesn't worry
me) then only shows on the screen the portion of the View wich fits
into the bounds specified in the WebView with (200,300). In other
words, I rotate in the ExtVebView but it behaves like if I would the
WebView one (cutting the web page to its dimmensions).

However, that's not the only one surprise (not the most interesting
one, at least for me). If I add a class wich extends TextView in the
main activity above the ExtWebView with the methods: setMinWidth(300)
and setMinHeight(300) (both of them inside the overrided onDraw
method) then ExtWebView shows the whole page rotated exactly like
expected, even behaves fine when sliding my finger on it, although the
portion of the web which before wasn't showed and yes now becomes
insensitive to my finger slidings. In a few words, with the
setMinWidth and setMinHeight methods the limits setted to 200x300 in
the WebView disappear. Is this a bug? Is there any other way of
achieving this effect? I`ve been looking inside the code of the
TextView and I think the question it is in the requestLayout() method
but I don't know where is implemented it's code.

Any help will be wellcome.

The code of ExtWebView is:

public class ExtWebView extends LinearLayout {

        public ExtWebView(Context context) {
                super(context);
                mContext = context;
                init();
        }

        public ExtWebView(Context context, AttributeSet params) {
                super(context, params);
                mContext = context;
                init();
        }

        private void init() {
                pagWeb = new WebView(mContext);
                pagWeb.getSettings().setJavaScriptEnabled(true);
                setWillNotDraw(false); //force the use of the OnDraw
method
                addView(pagWeb, 200, 300);
        }

       @Override
       protected void onDraw(Canvas canvas) {
                canvas.translate(0,320);
                canvas.rotate(-90);
                super.onDraw(canvas);
    }

}

The ExtTextView one:

public class ExtTextView extends TextView {
        public ExtTextView(Context context) {
                super(context);
                setText("Weird effect ...");
        }

       @Override
        protected void onDraw(Canvas canvas) {
                 canvas.save();

                 this.setMinHeight(300);
                 this.setMinWidth(300);

                 super.onDraw(canvas);
                 canvas.restore();
        }
}

and we add the views in the main activity with:

ExtWebView.loadURL("file:///sdcard/test.html")  //Loading of the web
page

addContentView(ExtWebView, new
LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));"

addContentView(ExtTextView, new
LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));"

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to