2015-02-08 75 views
0

如何将布局文件中的自定义SurfaceView旋转180度?以xml布局旋转SurfaceView

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
     <package.CustomSurfaceView 
     android:layout_width="fill_parent" 
     android:layout_height="0dp" 
     android:rotation="180" 
     /> 
</LinearLayout> 

不用说上面的代码不起作用。

回答

0

您无法通过XML(就像你注意到)做到这一点,

最好的选择是做它在画布上绘制之前,这样的:

canvas.rotate(180f); 
+0

但对于触摸然后输入? – Greyshack 2015-02-08 22:48:40

+0

那么你必须在onTouchEvent期间计算它来将X和Y翻转到另一侧。 – Budius 2015-02-08 22:52:02

+0

是的,我做到了,好的谢谢:)另外,我认为你写的部分错误,因为你必须保存画布,旋转,绘制,然后恢复。 – Greyshack 2015-02-08 23:07:42