【问题标题】:Android: Cannot set VideoView background to transparentAndroid:无法将 VideoView 背景设置为透明
【发布时间】:2013-12-21 15:21:39
【问题描述】:

我有一个 VideoView 播放一个形状不是矩形的视频(即带圆角的旋转圆柱体)。视频视图显示在具有背景颜色的 LinearLayout 中。我希望视频视图的背景是透明的,以便产生圆柱在背景颜色之上旋转而没有任何黑角的效果。 这就是我得到的:

这就是我想要得到的:

当然,你可能会问,我为什么不直接把视频的背景色设置成与容器的背景色相匹配,但我之所以要做到这一点,是因为我下一步要做的是有一个图像或图案作为容器的背景。我的布局xml如下:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#00aaff"
    android:orientation="vertical" >

    <VideoView
        android:id="@+id/surface_view"
        android:layout_width="254dp"
        android:layout_height="200px" />

</LinearLayout>

在试验过程中,我尝试为视频视图设置背景,但结果导致视频视图完全模糊。

谢谢。

【问题讨论】:

    标签: android android-videoview alpha-transparency


    【解决方案1】:

    VideoView 正在当前窗口上方打开一个单独的窗口。这是因为它是基于 SurfaceView 的。而且我们无法设置 alpha 或使用它执行动画,因为它没有与您的其他 UI 元素同步。

    所以: 您应该使用基于 TextureView 的视频播放器和 动画透明背景,将“设置 alpha”设置为 TextureView 您可以使用这些库并获得基于 TextureView 的视频播放器

    【讨论】:

    • 如果我设置了 alpha,整个视频就会变成透明的。我们怎样才能让黑色背景部分消失?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-02
    相关资源
    最近更新 更多