How to implement Picture in Picture (PIP) in Android?
Last Updated :
28 Mar, 2025
In this article, it is explained how to implement a Picture in Picture (PIP) in an Android application. We have seen in many apps such as Google Maps while using navigation that when we close the app, there is a floating screen that appears at the bottom right of the screen as shown in the image below. This screen is known as PIP (Picture in Picture) mode.

What is PIP (Picture in Picture) mode?
PIP is a special type of multi-window mode mainly used for activities that need to be active on screen but should not take up the whole screen space like watching videos, video calls, navigation, etc. It lets the user watch a video in a small window pinned to a corner of the screen (by default bottom right) while navigating between apps or browsing content on the main screen. Android 8.0 (API level 26) and above allows activities to launch in PIP mode.
The PIP window appears in the top-most layer of the screen. You can drag the PIP window to another location using some special toggles. When you tap on the window two special controls appear:
- a full-screen toggle (in the centre of the window) and
- a close button (an "X" in the upper right corner).
Step by Step Implementation
Step 1: Create a New Project
To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio.
Step 2: Declaring picture-in-picture support
By default, no activity has PIP mode enabled. This needs to be done via the Manifest file
<activity
android:name=".MainActivity"
android:supportsPictureInPicture="true"
android:configChanges="screenSize|screenLayout|orientation|smallestScreenSize"
...
>
...
</activity>
Step 3: Working with activity_main.xml
Now, in the layout file (activity_main.xml), we will have two components in the activity: a TextView and a Button.
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center"
tools:context=".MainActivity">
<Button
android:id="@+id/enter_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enter PIP"
/>
</LinearLayout>
Step 4: Working with MainActivity file
Now, let's add some code in MainActivity.java file. In this app, we will change the activity to PIP mode on a button click. First, we will get the display size using the getWindowManager(). After that using the function enterPictureInPictureMode() which should be provided with a PictureInPictureParams.Builder parameter.
MainActivity.java
package org.geeksforgeeks.demo;
import androidx.appcompat.app.AppCompatActivity;
import android.app.ActionBar;
import android.app.PictureInPictureParams;
import android.content.res.Configuration;
import android.graphics.Point;
import android.os.Bundle;
import android.util.Rational;
import android.view.Display;
import android.view.View;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
private Button enter;
ActionBar actionBar;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
actionBar = getActionBar();
enter = findViewById(R.id.enter_button);
enter.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view)
{
Display d = getWindowManager()
.getDefaultDisplay();
Point p = new Point();
d.getSize(p);
int width = p.x;
int height = p.y;
Rational ratio
= new Rational(width, height);
PictureInPictureParams.Builder
pip_Builder
= new PictureInPictureParams
.Builder();
pip_Builder.setAspectRatio(ratio).build();
enterPictureInPictureMode(pip_Builder.build());
}
});
}
}
MainActivity.kt
package org.geeksforgeeks.demo
import android.app.ActionBar
import android.app.PictureInPictureParams
import android.graphics.Point
import android.os.Build
import android.os.Bundle
import android.util.Rational
import android.widget.Button
import androidx.annotation.RequiresApi
import androidx.appcompat.app.AppCompatActivity
class MainActivity : AppCompatActivity() {
private lateinit var enter: Button
private var actionBar: ActionBar? = null
@RequiresApi(Build.VERSION_CODES.O)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
actionBar = getActionBar()
enter = findViewById(R.id.enter_button)
enter.setOnClickListener {
val d = windowManager.defaultDisplay
val p = Point()
d.getSize(p)
val width = p.x
val height = p.y
val ratio = Rational(width, height)
val pipBuilder = PictureInPictureParams.Builder()
pipBuilder.setAspectRatio(ratio).build()
enterPictureInPictureMode(pipBuilder.build())
}
}
}
Output:
Press the button to enable PIP mode for the activity.
Similar Reads
How to Implement TNImage Library in Android?
Android is an open-source operating system, based on the Linux kernel and used in mobile devices like smartphones, tablets, etc. Further, it was developed for smartwatches and Android TV. Each of them has a specialized interface. Android has been one of the best-selling OS for smartphones. Android O
3 min read
How to Implement Zoom In or Zoom Out in Android?
ImageView in Android is used to display images of different formats. Images are set according to the size of ImageView irrespective of the size of the image. However, ImageView does not provide a provision to zoom in or zoom out of the image. So in this article, we will show you how you could creat
2 min read
How to Implement Shapeable ImageView in Android?
In Android, ShapeableImageView is used to change the shape of your image to circle, diamond, etc. Also, you can set a corner radius to your ImageView. You can do much more by using this ShapeableImageView with minimal code. So in this article, we are going to make a ShapableImageView in android. By
5 min read
How to Resize Images Programmatically in Android?
There are many applications available on the net for performing image operations such as cropping, reducing image file size, or resizing the images to particular dimensions. Most of these applications are API based where the image is uploaded to anonymous servers, various functions are performed and
3 min read
Photo Picker in Android 13 with Example Project
In many android applications, we get to see that they are picking images from the user's device and displaying that images within the android application. For image picking, android applications use intent within the android application. In this article, we will take a look at How to implement Photo
3 min read
How to Build Image Filters like Instagram in Android?
Now a day many social media apps provide so many filters that we can use to make our image inside the app more beautiful and attractive. This type of feature is generally seen in Instagram, Snapchat, and many socials media apps. In this article, we will take a look at the implementation of this Inst
7 min read
How to Implement Chat Functionality in Social Media Android App?
This is the Part 14 of "Build a Social Media App on Android Studio" tutorial, and we are going to cover the following functionalities in this article: We are going to Create a Layout for chat & Send Messages in Chat.A user can send either a Message or an Image.A user can send an image either usi
15+ min read
PhotoView in Android with Example
In this article, PhotoView is added to android. PhotoView aims to help produce an easily usable implementation of a zooming Android ImageView using multi-touch and double-tap. Besides that, it has many more features like it notifying the application when the user taps on the photo or when the displa
2 min read
How to Add Text Drawable to ImageView in Android?
In many android apps, you will get to see a feature in which you can see a simple text is displayed inside an ImageView or you can get to see that a text is displayed in a specific image or a shape. Mostly this type of view is seen in the Contacts application which is present on your Android device.
5 min read
How to Resize a Bitmap in Android?
ImageViews are used within the android application to display different types of images. Many times images are displayed within the ImageView using bitmap instead of drawable files. In this article, we will take a look at How to Resize Bitmap in the android application to resize our image to be disp
3 min read