[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["没有我需要的信息","missingTheInformationINeed","thumb-down"],["太复杂/步骤太多","tooComplicatedTooManySteps","thumb-down"],["内容需要更新","outOfDate","thumb-down"],["翻译问题","translationIssue","thumb-down"],["示例/代码问题","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-07-27。"],[],[],null,["# Picture-in-picture (PiP) is a type of multi-window mode intended for activities\nthat play full-screen video. It lets the user watch a video in a small window\npinned to a corner of the screen while navigating between apps or browsing\ncontent on the main screen.\n**Figure 1:** Your users can continue their video experience even when not in your app\n\nTakeaways\n---------\n\n- Make sure UI elements are hidden and video playback continues when the activity is in PiP mode.\n- Disable seamless resizing for non-video content.\n- Video playback activities with minimal UI provide the best user experience.\n- Avoid showing anything except the video content.\n\nAdd support for picture-in-picture to your app\n----------------------------------------------\n\nBy default, the system does not automatically support PiP for apps and needs to\nbe declared to support the feature.\n\nThe PiP window appears in the topmost layer of the screen, in a corner chosen by\nthe system.\n\n### Controls\n\nBy default, Android provides PiP controls for closing the window, expanding it\nback to fullscreen, settings, and media playback. Your app can add custom\nactions and appropriate icon assets to allow users to interact with the PiP\ncontent.\n\nThe user can display these controls from the PiP window menu by tapping the\nwindow on a mobile device or selecting the menu from the TV remote. If an app\nhas an [active media session](/guide/topics/media-apps/working-with-a-media-session), controls for play, pause, next, and previous\nalso display. Read about how to [add these controls](/develop/ui/views/picture-in-picture#add_controls).\n\nIn PiP mode, your activity displays in a small window. Users cannot interact\nwith your app's other UI elements in this mode, and the details of small UI\nelements in the PiP window may be difficult to see.\n\n\nDefault PiP controls. \n\nExample of custom PiP controls.\n\n\u003cbr /\u003e\n\nUsage\n-----\n\nAllow users to continue watching their video not only within your app, but\ncontinue across their device. Your app controls when the current activity enters\nPiP mode--this can be an interaction such as leaving the current view or swiping\nup to go home.\n\nHere are some examples of possible actions:\n\n- An activity can enter PiP mode when the user taps the home button or swipes up\n to home. This is how Google Maps continues to display directions while the\n user runs another activity at the same time.\n\n **Figure 4:** PiP used to continue wayfinding experience\n- Your app can move a video into PiP mode when the user navigates back from the\n video to browse other content.\n\n- Your app can switch a video into PiP mode while a user watches the end of an\n episode of content. The main screen displays promotional or summary\n information about the next episode in the series.\n\n- Your app can provide a way for users to queue up additional content while they\n watch a video. The video continues playing in PiP mode while the main screen\n displays a content selection activity.\n\nUse an interaction pattern that compliments the viewing experience without\nbeing disruptive. For example, if a video is at the end of an episode of\ncontent, entering PiP when leaving the home screen will require additional user\naction to return and stop playback or navigate small controls.\n\nIn your app, a user might select a new video when browsing for content on the\nmain screen, while a video playback activity is in PiP mode. Play the new video\nin the existing playback activity in full screen mode, instead of launching a\nnew activity that might confuse the user.\n\n### Interaction patterns\n\nUsers can drag the PiP window to another location.\n\n**Single-tap** the window to display a full-screen toggle, a close button, a\nsettings button, and custom actions provided by your app (for example, play\ncontrols).\n\n\u003cbr /\u003e\n\n**Figure 5:** Default PiP controls\n\n\u003cbr /\u003e\n\n**Double-tap** the window to toggle between the current PiP size and the maximum\nor minimum PiP size---for example, double-tapping a maximized window minimizes\nit, and the converse is true as well.\n\n\u003cbr /\u003e\n\n**Figure 6:** Toggling between min and max size PiP with double-tap\n\n\u003cbr /\u003e\n\n**Stash** the window by dragging it to the left or right edge. To unstash the\nwindow, either tap the visible part of the stashed window or drag it out.\n\n\u003cbr /\u003e\n\n**Figure 7:** PiP stashed\n\n\u003cbr /\u003e\n\n**Resize** the PiP window using pinch-to-zoom.\n\n**Swipe** the PiP down to remove the window.\n\n\u003cbr /\u003e\n\n**Figure 8:** Swiping down\n\n\u003cbr /\u003e\n\n### Transitions\n\n#### Smooth enter to PiP animation\n\nA user triggering PiP mode causes the current activity to shrink from fullscreen\nto a small window, which continues showing the content without overlaying any\nUI.\n\nAndroid 12 added significant cosmetic improvements to the animated transitions\nbetween fullscreen and PiP windows. We strongly recommend implementing all\napplicable changes; once you've done so, these changes automatically scale to\nlarge screens such as foldables and tablets without any further required work.\n\nIf your app doesn't include these applicable updates, PiP transitions are still\nfunctional, but the animations are less polished. For example, transitioning\nfrom fullscreen to PiP mode can cause the PiP window to disappear during the\ntransition before it reappears when the transition is complete.\n\nStarting in Android 12, the\n[`PictureInPictureParams.Builder.setAutoEnterEnabled(true)`](/reference/android/app/PictureInPictureParams.Builder#setAutoEnterEnabled(boolean)) flag provides\nmuch smoother animation for transitioning to video content in PiP mode using\ngesture navigation---for example, when swiping up to home from fullscreen.\nWe recommend this if your app falls in the `ENTERTAINMENT`, `COMMUNICATION`, or\n`VIDEO_PLAYER` app category.\n\nIf your app doesn't include this change, PiP transitions with gesture navigation\nare still functional but the animations are less polished. Video 1 shows an\nexample of this: the window shrinks into the app icon and disappears, then\nreappears when the transition is complete.\n\n\nAlas, your browser doesn't support HTML5 video. That's OK! You can still [download the video](/static/images/design/ui/mobile/PiP-video-1-before-setAutoEnterEnabled.mp4) and watch it with a video player.\n\nLess polished transition experience when PiP does not have\n`setAutoEnterEnabled` properly implemented \nAlas, your browser doesn't support HTML5 video. That's OK! You can still [download the video](/static/images/design/ui/mobile/PiP-video-2-after.mp4) and watch it with a video player.\n\nPolished transition experience with `setAutoEnterEnabled` added to the app.\n\n\u003cbr /\u003e\n\n| **Note:** Setting `setAutoEnterEnabled(true)` also disables seamless resizing for non-video content---for example, maps.\n\n#### Smooth video visuals\n\nWhen we introduced PiP in Android 8.0, [`sourceRectHint`](/reference/android/app/PictureInPictureParams.Builder#setSourceRectHint(android.graphics.Rect)) indicated the area\nof the activity that is visible following the transition into PiP---for\nexample, the video view bounds in a video player. Starting with Android 12,\nthe OS uses `sourceRectHint` to implement a much smoother animation both when\nentering and exiting PiP mode.\n\nIf your app doesn't provide a proper `sourceRectHint`, PiP transitions are still\nfunctional but animations are less polished. For example, video 3 shows a less\npolished example of a transition from fullscreen to PiP mode: after the\nfullscreen window shrinks to the PiP window, it's covered by a black overlay\nbefore revealing the video once again. \nAlas, your browser doesn't support HTML5 video. That's OK! You can still [download the video](/static/images/design/ui/mobile/PiP-video-3-before-sourceRectHint.mp4) and watch it with a video player. **Video 3:** Less polished transition experience when PiP does not have `sourceRectHint` properly implemented\n\nTo see an example of how PiP animation looks when `sourceRectHint` is properly\nimplemeneted, see video 2 in the preceding section.\n\nRefer to the [Android Kotlin PictureInPicture sample](https://github.com/android/media-samples/tree/main/PictureInPictureKotlin/#readme) as a\nreference for enabling a polished transition experience.\n\nFor more on implementing PiP, see the [Picture-in-picture developer\ndocumentation](/develop/ui/views/picture-in-picture)."]]