Android: Adding View/Managing Layout

Brightcove Player
Video Cloud
Device SDK Developer
Develop with the Native SDKs

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.