Reputation: 12989
I have some content for a WebView that would look better in landscape format. I've found solutions which would enable me to force landscape orientation when displaying the WebView, which achieves the goal, but in a way that I don't like.
In particular, I don't think it's a great user experience to have the actual screen rotation changed suddenly, without warning and without having requested this, so that everything sort of spins in front of your eyes, with the status bar etc moving from top to side.
I'd prefer that the actual screen rotation is left alone, so that it remains in portrait orientation if that is what it is presently set. All that needs to happen is that the page within the WebView is displayed sideways, in landscape orientation.
Is that possible?
Upvotes: 2
Views: 3257
Reputation: 6523
You can try create a custom WebView like:
public class VWebView extends WebView {
final boolean topDown = true;
public VWebView(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public void draw(Canvas canvas) {
if (topDown) {
canvas.translate(getHeight(), 0);
canvas.rotate(90);
} else {
canvas.translate(0, getWidth());
canvas.rotate(-90);
}
canvas.clipRect(0, 0, getWidth(), getHeight(), android.graphics.Region.Op.REPLACE);
super.draw(canvas);
}
}
XML:
<com.my.package.VWebView
android:id="@+id/myview"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</com.my.package.VWebView>
Upvotes: 1