首页 > 解决方案 > 在 Android 上构建圆框相机

问题描述

我已经为android构建了一个相机应用程序。我面临的问题是使相机框架变为圆形而不是方形或全屏。我试图使布局将其形状更改为圆形,但它没有用。布局是->

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_height="match_parent" android:layout_width="match_parent"
                android:orientation="vertical"
    android:gravity="center"
    android:background="#541358">
    <FrameLayout android:layout_width="350dp"
                 android:layout_height="350dp"
        android:layout_gravity="center"
        android:background="@drawable/backshape"
                 android:id="@+id/container">
    </FrameLayout>
</LinearLayout>

这是布局设计 这就是相机实际的样子(注意相机仍然是方形的,但我需要它是圆形的)

很感谢任何形式的帮助。

标签: androidandroid-layoutandroid-fragmentsandroid-cameraandroid-camera2

解决方案


你的框架布局可以是这样的

        <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <SurfaceView
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
        <View
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@drawable/backShape"></View>
    </FrameLayout>

推荐阅读