如何在Videoview周围添加5px边框?

时间:2016-10-01 22:47:48

标签: android padding android-xml android-videoview android-background

我有以下视频观点:

 <VideoView
        android:layout_width="200dp"
        android:layout_height="316dp"
        android:layout_below="@+id/instructions"
        android:layout_centerHorizontal="true"
        android:id="@+id/instructionsvideo" />

它工作正常,但我想要一条细黑线。我尝试将padding属性设置为5px并将背景设置为如下颜色:

android:padding="5dp"
android:background="@color/black"

但这只会使整个视频视图变黑并阻止视频显示,如何为视频视图添加边界?

2 个答案:

答案 0 :(得分:2)

关于保证金,您可以在android:layout_margin="5dp"本身设置标记 VideoView 。结果如下:

enter image description here

Layout

的XML代码
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent" android:layout_height="match_parent"
    >

    <FrameLayout
        android:layout_width="200dp"
        android:layout_height="316dp"
        android:background="@android:color/black"
        android:layout_gravity="center">
        <VideoView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/videoView"
            android:layout_gravity="center"
            android:layout_margin="5dp"/>

    </FrameLayout>

</FrameLayout>

关于黑色背景,我认为最好的方法是使用VideoView周围的框架,我同意@Mariano Di Stefano那里(至少它很简单)

答案 1 :(得分:0)

你可以将VieoView放在其他一些(RelativeLayout,LinearLayout甚至FrameLayout)中并设置margin&amp;此父级的黑色背景(当然,将视频中心放在两个方向上)。