这是我第一次在这里发帖。我想问一下您是否知道如何像 Instagram 或 BeReal 那样制作相机取景器的布局(带有圆角边缘)。下面附上示例输出。
这是我的相机视图代码:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".InterpreterFragment">
<androidx.camera.view.PreviewView
android:id="@+id/viewFinder"
android:layout_width="match_parent"
android:layout_height="500dp" />
</FrameLayout>
我正在尝试搜索
<shape>
视图,但我似乎无法使其工作。谢谢。
我尝试通过创建可绘制的形状来使用
<shape>
。代码如下:
<?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="20dp"
android:bottomLeftRadius="20dp"
android:topLeftRadius="20dp"
android:topRightRadius="20dp"/>
<solid android:color="#00000000" />
</shape>
并尝试将其设置为相机视图的背景或前景,但它不起作用。
我几个月前解决了这个问题,但如果有人感兴趣,请使用 CardView 并将
PreviewView
放入其中。
<androidx.cardview.widget.CardView
android:id="@+id/viewfinder_cardview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginHorizontal="5dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="100dp"
app:cardCornerRadius="20dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" >
<androidx.camera.view.PreviewView
android:id="@+id/viewFinder"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</androidx.cardview.widget.CardView>