我想制作一个圆形的SurfaceView,搜索了很多但没有找到一个好的解决方案。目前我的处理方式是将SurfaceView放入FrameLayout中,然后在其上面添加另外一个View,可以使用PNG遮罩或者是形状XML drawable。下面是代码:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="140dp"
android:layout_height="140dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:background="#000"
android:orientation="vertical"
android:visibility="visible" >
<FrameLayout
android:id="@+id/videorecordview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_weight=".2" >
<SurfaceView
android:id="@+id/surfaceView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</FrameLayout>
</LinearLayout>
<LinearLayout
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:background="@drawable/rounded"
android:orientation="vertical" >
</LinearLayout>
</RelativeLayout>
但这不是一个好的解决方案,也不能完美地工作。我想自定义SurfaceView成为圆形形状。任何帮助将不胜感激。谢谢 :)