如何制作圆角的Surfaceview [英] How to make a rounded surfaceview

查看:136
本文介绍了如何制作圆角的Surfaceview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试制作一个圆形的Surfaceview.我已经搜索了很多,但是找不到很好的解决方案.我现在正在做的是,将SurfaceView放入FrameLayout,然后在其上面放置另一个View,可以使用PNG蒙版或可绘制的xml形状.在这里

I'm trying to make a rounded shaped surfaceview. I've searched a lot but i couldn't find a good solution. what i'm doing right now is that, I've put the SurfaceView into a FrameLayout, then another View on top of it, either with a PNG mask, or a shape xml drawable. here it is

<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定制为圆形.任何帮助将非常感激.谢谢:)

But this is not a good solution and it is also not working perfectly. I want to customize surfaceview to a rounded shape. any help would be much appreciated. Thank you :)

推荐答案

您无法更改SurfaceView的Surface的形状.

You can't change the shape of the SurfaceView's Surface.

SurfaceView有两个部分,Surface和View.视图部分的工作方式与其他任何视图一样.默认情况下,它只是充当透明的孔",在布局中创建一个窗口.应用程序将所有视图呈现到单个图层上.

A SurfaceView has two parts, the Surface and the View. The View part works like any other View. By default, it just acts as a transparent "hole", creating a window in the layout. All Views are rendered by the app onto a single layer.

Surface部件是一个单独的层,位于View层的后面(除非您显式更改Surface的Z顺序),因此您只能在它通过" View层的透明区域显示"的位置看到它.您可以在视图"图层上进行绘制以遮盖表面"的某些部分,但不能更改表面"图层本身的形状.图层是矩形的.

The Surface part is a separate layer that sits behind the View layer (unless you explicitly change the Surface's Z order), so you only see it where it "shows through" transparent areas of the View layer. You can draw on the View layer to mask portions of the Surface, but you can't change the shape of the Surface layer itself. Layers are rectangular.

在许多情况下,可以使用 TextureView 代替SurfaceView.TextureView提供了更大的灵活性,因为它是由应用程序渲染到View层上的,但效率却不如SurfaceView.

In many situations a TextureView can be used in place of a SurfaceView. TextureView offers greater flexibility because it's rendered by the app onto the View layer, but can be less efficient than SurfaceView.

更多信息可在Android 图形架构文档中找到.

More information can be found in the Android graphics architecture doc.

这篇关于如何制作圆角的Surfaceview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆