android - 如何在 Android TV 应用程序中设置画中画 (PiP) 的位置?

标签 android android-8.0-oreo android-tv android-picture-in-picture

有没有办法将画中画 (PiP) 窗口放在右上角(或其他地方)而不是屏幕的右下角(默认情况下)?或以编程方式设置确切位置?

最佳答案

引用下面的提交,这个设置可以帮助“config_defaultPictureInPictureGravity”

你可以引用https://cs.android.com/android/platform/superproject/+/master:frameworks/base/core/java/android/view/Gravity.java;l=45找出你需要的值(value)

例如重力.TOP | Gravity.RIGHT 为 0x35

commit 06868c37df46c0c973a96a0a25b1f301384db4be
Author: Winson <winsonc@google.com>
Date:   Wed Oct 12 21:08:18 2016 -0700

    Changing initial PIP bounds specifications.
    
    - Change from a absolute bounds to a size, gravity and inset to
      allow easier tweaking of initial pinned stack bounds.
    
    Test: android.server.cts.ActivityManagerPinnedStackTests
    Test: #testPinnedStackDefaultBounds
    Test: #testPinnedStackMovementBounds
    
    Change-Id: I82a102bbd2d83259c6c84915071d1a16728e3aa7

diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml
index c40436a5bda..30dcfb081d8 100644
--- a/core/res/res/values/config.xml
+++ b/core/res/res/values/config.xml
@@ -2482,8 +2482,17 @@
          -->
     <integer name="config_navBarOpacityMode">0</integer>
 
-    <!-- Default bounds [left top right bottom] on screen for picture-in-picture windows. -->
-    <string translatable="false" name="config_defaultPictureInPictureBounds">"0 0 100 100"</string>
+    <!-- Default insets [LEFT/RIGHTxTOP/BOTTOM] from the screen edge for picture-in-picture windows.
+         These values are in DPs and will be converted to pixel sizes internally. -->
+    <string translatable="false" name="config_defaultPictureInPictureScreenEdgeInsets">10x10</string>
+
+    <!-- Max default size [WIDTHxHEIGHT] on screen for picture-in-picture windows to fit inside.
+         These values are in DPs and will be converted to pixel sizes internally. -->
+    <string translatable="false" name="config_defaultPictureInPictureSize">216x135</string>
+
+    <!-- The default gravity for the picture-in-picture window.
+         Currently, this maps to Gravity.BOTTOM | Gravity.RIGHT -->
+    <integer name="config_defaultPictureInPictureGravity">0x55</integer>

关于android - 如何在 Android TV 应用程序中设置画中画 (PiP) 的位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53302777/

相关文章:

java - 语音识别API : How to get the voice features (MEL Coefficients)

android - 无法在 OREO 中获取默认帐户

java - 在 Android Oreo 8.x 中更改 WiFi 热点的 SSID 和密码

android - 检测 Google Cast 的使用情况

android - 如何在自己的应用程序中使用 3rd 方 TvProvider 对象?

android - 如何更改Android模拟器的默认语言?

javascript - Android webview 点击

c# - 如何使对象/层忽略附近的裁剪平面?

android - 如果我的应用程序针对牛轧糖设备,startService() 仍然有效

android - 在 Android TV 中使用 Youtube API