網站首頁 編程語言 正文
基礎畫中畫
manifest 設置
為了適配開啟畫中畫狀態時窗口的大小尺寸變化合理,我們需要修改 activity 中的對應屬性
請為您的主 activity 添加如下屬性
- configChanges 當 activity 尺寸變化是走出適配
- launchMode 若使用畫中畫,則必須單任務執行
- resizeableActivity 確保可以重新調節 activity 尺寸
- supportsPictureInPicture 開啟畫中畫支持
<activity android:name=".MainActivity" android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation" android:exported="true" android:launchMode="singleTask" android:resizeableActivity="true" android:supportsPictureInPicture="true"> <meta-data android:name="android.app.lib_name" android:value="" /> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity>
布局
即一線性布局,配上 videoview,使他充滿整個屏幕寬高
<?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" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <VideoView android:id="@+id/video" android:layout_width="match_parent" android:layout_height="match_parent" /> </LinearLayout>
開啟畫中畫
定義一個開啟畫中畫的方法 minimize
private fun minimize() { // 畫中畫builder var builder = PictureInPictureParams.Builder() // rational設定尺寸大小 val info = Rational(video.width, video.height) builder.setAspectRatio(info).build() // 開啟畫中畫 enterPictureInPictureMode(builder.build()) }
為了簡化使用,我們定義:在按下導航欄的 home 鍵時,整個 activity 縮小成畫中畫形式,并僅展示 videoview
這一步驟可以通過重寫 onUserLeaveHint
方法實現
override fun onUserLeaveHint() { minimize() }
上傳一個你喜歡的視頻,插入組件,運行程序即可
目前還未做 UI 優化,所以整體結構還是很丑
原文鏈接:https://blog.csdn.net/delete_you/article/details/127730705
相關推薦
- 2023-04-01 pytorch和numpy默認浮點類型位數詳解_python
- 2023-05-08 Android事件分發之View事件處理關鍵及示例分析_Android
- 2022-05-10 .NET實現異步編程async和await_實用技巧
- 2022-04-24 C++vector的用法你都知道嘛_C 語言
- 2022-04-27 前端實現滑動按鈕AJAX與后端交互的示例代碼_AJAX相關
- 2023-07-07 什么是 Spring 框架?使用 Spring 框架的好處是什么?Spring 框架中用到了哪些設計
- 2022-06-07 教你使用Jenkins集成Harbor自動發布鏡像_docker
- 2022-11-05 python中的bisect模塊與二分查找詳情_python
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支