網站首頁 編程語言 正文
基礎畫中畫
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
相關推薦
- 2022-07-23 解析go語言調用約定多返回值實現原理_Golang
- 2022-08-30 C語言深入詳解四大內存函數的使用_C 語言
- 2022-09-23 React深入了解原理_React
- 2022-11-05 GO?CountMinSketch計數器(布隆過濾器思想的近似計數器)_Golang
- 2022-07-29 C++超詳細講解字符串類_C 語言
- 2022-06-25 C#設計模式之適配器模式與裝飾器模式的實現_C#教程
- 2023-05-22 關于PyTorch中nn.Module類的簡介_python
- 2022-08-29 .NET?Core使用Eureka實現服務注冊_實用技巧
- 最近更新
-
- 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同步修改后的遠程分支