Floating Templates - Android

Choosing the Floating player mode in the dashboard, allows the player to stay present on the screen and keep playing even after its original position has been scrolled out of view by “floating” at a fixed position on the screen. The floating position can also be selected in the dashboard from a pre defined set of options.

Floating Scope

In general, the floating behavior and configuration is controlled from the dashboard but in order to provide flexibility to the application developers, they are the ones who define the borders that will limit the floating behavior by providing a Floating Scope. Here's a visual illustration:

<?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/main_layout" android:layout_width="match_parent" android:layout_height="match_parent"> <include android:id="@+id/app_bar" layout="@layout/app_bar" /> <FrameLayout android:id="@+id/floating_scope" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/aniview_gray" > <androidx.core.widget.NestedScrollView android:id="@+id/screen_content" android:layout_width="match_parent" android:layout_height="wrap_content" > <!--Screen content here--> </androidx.core.widget.NestedScrollView> </FrameLayout> </androidx.constraintlayout.widget.ConstraintLayout>

 

The scope is a ViewGroup, preferably a FrameLayout, that should be provided by invoking AdPlayerPlacement.setFloatingScope(scopeViewGroup):

Important: Floating behavior will not be available without providing a scope!

Make sure the floating scope doesn’t extend beyond the limits of the visible area. A scope that extends beyond the limits of the visible area will cause the player to float off the screen and be cut off or even not visible at all.

Kotlin

val floatingScope = root.findViewById<ViewGroup>(R.id.floating_scope) root.findViewById<AdPlayerPlacementView>(R.id.ad_1).setFloatingScope(floatingScope)

Java

ViewGroup floatingScope = root.findViewById(R.id.floating_scope) root.findViewById(R.id.ad_1).setFloatingScope(floatingScope)

Note that a floating scope must allow more than one child view and therefore cannot be one of the following types: RecyclerView, ListView, ScrollView, NestedScrollView.