Android : Android: How to make circle-shaped Camera Preview?

on Wednesday, March 18, 2015


How can I create circle/oval-shaped or round-cornered Camera Preview like this (the circle in the middle should be camera preview)?


enter image description here


The background has to be visible, so that's why I cannot use solutions like add android:background as a shape rectangle with radius like this:



<?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>


and when I try to set android:background as oval xml to the SurfaceView, it doesn't work either:



<?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>


If it is possible to somehow extend SurfaceView and use it, what should I rewrite please?


0 comments:

Post a Comment