【问题标题】:Android round surface view for video recording用于视频录制的 Android 圆形表面视图
【发布时间】:2014-07-01 08:11:05
【问题描述】:

是否有可能使用圆形表面视图而不是矩形视图?如果输出是 640x480 则不是问题。

提前致谢。

【问题讨论】:

  • 不确定你在问什么——你不能在 SurfaceView 上放一个遮罩吗?
  • 把 SurfaceView 放到 FrameLayout 中,然后在上面放另一个 View,可以是 PNG 掩码,也可以是 shape xml drawable...
  • 成功了,谢谢!不得不调用bringToFront()!我使用了相对布局而不是框架布局!

标签: android surfaceview geometry rounding


【解决方案1】:

将 SurfaceView 放入 FrameLayout,然后在其上放置另一个 View,可以使用 PNG 掩码,也可以使用可绘制的形状 xml。

【讨论】:

  • 有没有一个聪明的方法来做到这一点,然后在圆形视频中添加高程和圆形阴影,看起来还不错(材料设计):(
  • @Lo-Tan:我会使用 9-patch 来构建遮罩(带有你想要的阴影)并在 SurfaceView 上使用它。
  • 我实际上能够通过扩展类和覆盖 dispatchDraw (stackoverflow.com/a/14294979/269876) 将表面视图剪辑成一个圆形(stackoverflow.com/a/14294979/269876)这让我的视频视图只有一个视图,这使得高程和阴影更直接。 :) 谢谢!
  • 虽然抗锯齿(或缺乏抗锯齿)有点粗糙,但无论如何我可能会求助于面具和九个补丁......
  • @Lo-Tan 谢谢你的链接。还有一个完整的例子:stackoverflow.com/a/31064523/1819810
【解决方案2】:

只需在 Cardview 中添加 surfaceview 并添加以下参数:

app:cardCornerRadius="@dimen/_200sdp"
app:cardPreventCornerOverlap="false"


<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 
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="com.daasuu.sample.SquareActivity">

<androidx.cardview.widget.CardView
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:layout_margin="@dimen/_12sdp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintDimensionRatio="1:1"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:cardCornerRadius="@dimen/_200sdp"
    app:cardPreventCornerOverlap="false">

    <!--Add here surfaceview or textureview -->

</androidx.cardview.widget.CardView>
  


</androidx.constraintlayout.widget.ConstraintLayout>

【讨论】:

    猜你喜欢
    • 2014-07-19
    • 2016-08-02
    • 2014-04-07
    • 2021-02-05
    • 1970-01-01
    • 2015-04-28
    • 2017-07-19
    • 1970-01-01
    • 2017-04-23
    相关资源
    最近更新 更多