简体   繁体   English

如何在Android中创建圆角SurfaceView

[英]How to create rounded corner surfaceview in android

I want to make a surface view which can have rounded corners. 我想制作一个可以带有圆角的表面视图。 This surface view will be useful to render the video camera. 该表面视图对于渲染摄像机很有用。

I have already tried adding the surface view in the CardView with this code. 我已经尝试使用此代码在CardView中添加表面视图。

<android.support.v7.widget.CardView 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/cvCard"
    android:layout_width="150dp"
    android:layout_height="150dp"
    android:clipChildren="true"
    android:clipToPadding="false"
    app:cardCornerRadius="15dp"
    app:cardPreventCornerOverlap="false"
    app:cardUseCompatPadding="false">

    <Surfaceview is Added Programatically>

</android.support.v7.widget.CardView>

The result of this code is this image . 该代码的结果就是该图像 As you can see in the round corners the surface view is still visible. 正如您在圆角中看到的那样,表面视图仍然可见。 It is not entirely round within the card view and it always comes in rectangle shape. 在卡片视图中,它不是完全圆形的,并且总是呈矩形。

So is there any way to achieve the rounded corner Surfaceview? 那么有没有办法实现圆角Surfaceview?

You can not change directly surface view corner (Shape). 您不能直接更改surface view角(形状)。 But you can change your CardView corner by using 但是您可以使用以下方法更改CardView角落

app:cardCornerRadius="10dp" 
app:cardPreventCornerOverlap="false"

and set the SurfaceView match_parent that can cover the cardView . 并设置可以覆盖cardViewSurfaceView match_parent

Why you cannot change surface view shape? 为什么不能更改表面视图形状? The answer is here 答案在这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM