android webview 横竖屏_横向显示WebView无需旋转屏幕
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..
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?
解决方案
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:
android:id="@+id/myview"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐


所有评论(0)