My app uses a camera surface view layout with a size of 150 X 150. I need to show the surface corner is arc type. how to set the corner in camera.
Hi have a look at this code.
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle" >
<corners android:radius="15dip" />
<solid android:color="#404f64" />
<stroke android:width="2dp" android:color="#bebfc1"/>
</shape>
</item>
</layer-list>
set this as like below in your surface view.
android:background="@layout/rounded"
After more search i try to write code with cardView it worked for me .
Add dependencies :
implementation 'androidx.appcompat:appcompat:1.0.0'
implementation 'androidx.cardview:cardview:1.0.0'
Add code to xml :
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="270dp"
app:cardCornerRadius="10dp"
app:cardPreventCornerOverlap="false">
<SurfaceView
android:id="@+id/camera_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</androidx.cardview.widget.CardView>
Check out this tutorial on how to create an Android shape and apply that shape to your layout: http://www.vogella.com/blog/2011/07/19/android-shapes/
Specifically you use the <corners>
attribute of the <shape>
to create rounded corners, see example below from the above referenced tutorial:
<corners
android:bottomRightRadius="7dp"
android:bottomLeftRadius="7dp"
android:topLeftRadius="7dp"
android:topRightRadius="7dp"
/>
UPDATE 2 - This worked for me:
drawable-hdpi/rounded.xml:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke android:width="2dp" android:color="#FFFFFFFF" />
<corners
android:bottomRightRadius="7dp"
android:bottomLeftRadius="7dp"
android:topLeftRadius="7dp"
android:topRightRadius="7dp"/>
<solid android:color="#00000000" />
</shape>
drawable-hdpi/solid.xml:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke android:width="2dp" android:color="#FFFFFFFF" />
<solid android:color="#00000000" />
</shape>
drawable-hdpi/rounded_inside_corners.xml:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:drawable="@drawable/rounded" />
<item android:drawable="@drawable/solid" />
</layer-list>
Then in my activity layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/my_shape"
tools:context=".CameraActivity" >
<SurfaceView
android:id="@+id/surfaceView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/rounded_inside_corners"
android:layout_above="@+id/linearLayout1" />
<FrameLayout
android:id="@+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:orientation="horizontal" >
<Button
android:id="@+id/buttonTakePicture"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_gravity="center_horizontal"
android:background="@drawable/camera_click_256"
android:gravity="center_horizontal" />
</FrameLayout>
</RelativeLayout>
Which results in: