• Android画中画


    基础画中画

    manifest 设置

    为了适配开启画中画状态时窗口的大小尺寸变化合理,我们需要修改 activity 中的对应属性

    请为您的主 activity 添加如下属性

    1. configChanges 当 activity 尺寸变化是走出适配
    2. launchMode 若使用画中画,则必须单任务执行
    3. resizeableActivity 确保可以重新调节 activity 尺寸
    4. 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>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18

    布局

    即一线性布局,配上 videoview,使他充满整个屏幕宽高

    
    <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>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13

    开启画中画

    定义一个开启画中画的方法 minimize

    private fun minimize() {
        // 画中画builder
        var builder = PictureInPictureParams.Builder()
        // rational设定尺寸大小
        val info = Rational(video.width, video.height)
        builder.setAspectRatio(info).build()
        // 开启画中画
        enterPictureInPictureMode(builder.build())
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    为了简化使用,我们定义:在按下导航栏的 home 键时,整个 activity 缩小成画中画形式,并仅展示 videoview

    这一步骤可以通过重写 onUserLeaveHint 方法实现

    override fun onUserLeaveHint() {
        minimize()
    }
    
    • 1
    • 2
    • 3

    上传一个你喜欢的视频,插入组件,运行程序即可
    目前还未做 UI 优化,所以整体结构还是很丑


  • 相关阅读:
    在Express框架使用ORM模型访问关系型数据库
    HiveSQL中last_value函数的应用
    数据大瓶解决方案scale
    Springboot整合之Shiro和JWT技术实现无感刷新
    实验六 并行口8255的使用—LED静态显示
    瑞吉外卖(28)- 用户下单功能开发(功能完结篇)
    Day 28:2748. 美丽下标对的数目
    企业部门网络规划设计(课程报告+拓扑图源文件)
    Centos7单机部署zookeeper与kafka整体步骤,附上安装测试
    Vue 获取/设置指定组件高度
  • 原文地址:https://blog.csdn.net/delete_you/article/details/127730705