如果想僅旋轉的WebView,沒有別的,創建一個自定義的WebView這樣的:
public class VerticalWebView extends WebView {
final boolean topDown = true;
public VerticalWebView(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);
}
}
(更改topDown
爲false,如果你想旋轉的其他方式)
現在簡單地在你的XML中使用它如下:
<com.my.package.VerticalWebView
android:id="@+id/myview"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</com.my.package.VerticalWebView>
請記住,這只是旋轉視圖顯示在s creen和任何鏈接等將無法工作,因爲它不會將觸摸座標重新映射到相應點的新位置。
你爲什麼要這麼做? –
我編輯了更多的細節問題@RaghavSood –