我正在尝试制作圆形表面 View 。我搜索了很多,但找不到好的解决方案。我现在正在做的是,我将 SurfaceView 放入 FrameLayout,然后在其顶部放置另一个 View,带有 PNG 掩码或形状 xml 可绘制对象。在这里
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="140dp"
android:layout_height="140dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:background="#000"
android:orientation="vertical"
android:visibility="visible" >
<FrameLayout
android:id="@+id/videorecordview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_weight=".2" >
<SurfaceView
android:id="@+id/surfaceView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</FrameLayout>
</LinearLayout>
<LinearLayout
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:background="@drawable/rounded"
android:orientation="vertical" >
</LinearLayout>
</RelativeLayout>
但这不是一个好的解决方案,而且它也不能完美地工作。我想将 surfaceview 自定义为圆形。任何帮助将非常感激。谢谢:)
最佳答案
一点技巧。将表面 View 放在卡片 View 中。
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/margin_normal"
app:cardCornerRadius="10dp"
app:cardPreventCornerOverlap="false">
<SurfaceView
android:id="@+id/surfaceView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="@dimen/margin_normal" />
</android.support.v7.widget.CardView>
不要忘记将此添加到您的 gradle 文件中以使用 CardView
compile 'com.android.support:cardview-v7:25.0.1'
还有这两行在卡片 View 中
app:cardCornerRadius="10dp"
app:cardPreventCornerOverlap="false"
干杯快乐编码
关于android - 如何制作圆形的表面 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36564025/