Product Updates | Contact Support | System Status
Page Contents

    Android: Adding View/Managing Layout

    In this topic, you will learn how to manage the layout of a View added to the BrightcoveVideoView.

    Understanding layouts

    Before working with the Brightcove Native SDK for Android, it is a good idea to understand how to manage and customize layouts in your Android app.

    Start by reviewing the Android Developer User Interface guide.

    Overriding layout params

    The BrightcoveVideoView is the parent class of the BrightcoveExoPlayerVideoView.

    If you’re adding a View to the BrightcoveVideoView, then you need to override the setLayoutParams() method on the View child to apply only the layout params that make sense for the View child.

    Here is an example with the setLayoutParams() method:

    public void setLayoutParams(ViewGroup.LayoutParams layoutParams) {
        Log.v(TAG, "setLayoutParams: " + layoutParams);
        if (layoutParams != null) {
            int childCount = getChildCount();
            FrameLayout.LayoutParams frameLayoutParams =
                new FrameLayout.LayoutParams(layoutParams.width, layoutParams.height);
            frameLayoutParams.gravity = Gravity.CENTER;
            for (int i = 0; i < childCount; i++) {

    This allows the SurfaceView and the ImageView to get the layout params specified for the BrightcoveVideoView.

    Although it is possible to apply the layout params only to the SurfaceView and ImageView children, it would be difficult for additional children to react when the BrightcoveVideoView has its layout params updated.

    Brightcove suggests overriding setLayoutParams() in the LinearLayout child so that it passes through the width, but leaves the height and gravity unmodified.

    When to add a View

    Applications to add a View in the BrightcoveExoPlayerVideoView can be varied depending on the objective to add an object in front of the Player. For example, you may use views to add/remove TextViews to display the captions, or to add a layout for the controller in the App.

    The BrightcoveExoPlayerVideoView variant extends from the BaseVideoView which extends the Android FrameLayout. This means you could add a view to the BrightcoveExoPlayerVideoView the same way you would do it to a FrameLayout.

    Here is an example in the activity_main.xml file of an Android App:

    <LinearLayout xmlns:android=""
        tools:context=".MainActivity" >
                    android:text=“HELLO WORLD”

    Page last updated on 28 Sep 2020