Android:如何制作圆形相机预览?

Jak*_*sky 7 camera android preview surfaceview

如何创建像这样的圆形/椭圆形或圆角相机预览(中间的圆圈应该是相机预览)?

在此输入图像描述

伦敦图像用按钮和视图代表ui的其余部分,因此它必须是整体可见的,这就是为什么我不能使用像这样添加android:background为半径的形状矩形的解决方案:

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="#FFFFFF"/>
    <stroke android:width="3dip" android:color="#B1BCBE" />
    <corners android:radius="50dip"/>
    <padding android:left="0dip" android:top="0dip" android:right="0dip" android:bottom="0dip" />
</shape>
Run Code Online (Sandbox Code Playgroud)

当我尝试将android:background椭圆形xml 设置为SurfaceView时,它也不起作用:

<?xml version="1.0" encoding="utf-8"?>
<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval">

    <size
        android:width="120dp"
        android:height="120dp"/>

    <stroke
        android:color="#FF000000"
        android:width="2dp" />
</shape>
Run Code Online (Sandbox Code Playgroud)

如果有可能以某种方式扩展SurfaceView并使用它,我应该重写什么?

小智 0

嗯,我认为最简单的方法是通过 xml 将 imageView 放在 SurfaceView 示例之上:

<RelativeLayout ....>
  <SurfaceView ... />
  <ImageView ... />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)