随着手机屏幕越来越大,单手操作手机越来越难,所以一些大厂早就开始研究多窗口,如iphone、samsung的单手模式,作为一个发展趋势google肯定也不会不考虑用户的体验,所以在android N中增加了多窗口的操作。

本编通过android官方给出的示例结合api指南及前人分析来研究一下android 的多窗口操作。

示例Github

API指南

博客

用户可以通过以下方式切换到多窗口模式:

  • 若用户打开 Overview 屏幕并长按 Activity 标题,则可以拖动该 Activity 至屏幕突出显示的区域,使Activity 进入多窗口模式。
  • 若用户长按 Overview 按钮,设备上的当前 Activity 将进入多窗口模式,同时将打开 Overview屏幕,用户可在该屏幕中选择要共享屏幕的另一个 Activity。

上面是github上示例的UI

按照它的显示我们一个一个分析

1、首先 start basic Default Activity 打开的是默认的Activity

public void onStartBasicActivity(View view) {
        Log.d(mLogTag, "** starting BasicActivity");

        // Start an Activity with the default options in the 'singleTask' launch mode as defined in
        // the AndroidManifest.xml.
        startActivity(new Intent(this, BasicActivity.class));

    }

这个和正常的activity一样。

2、Start unresizeable Activity

 public void onStartUnresizableCliconStartBasicActivityk(View view) {
        Log.d(mLogTag, "** starting UnresizableActivity");

        /*
         * This activity is marked as 'unresizable' in the AndroidManifest. We need to specify the
         * FLAG_ACTIVITY_NEW_TASK flag here to launch it into a new task stack, otherwise the
         * properties from the root activity would have been inherited (which was here marked as
         * resizable by default).
        */
        Intent intent = new Intent(this, UnresizableActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
    }
在xml中
<activity
            android:name="com.android.multiwindowplayground.activities.UnresizableActivity"
            android:resizeableActivity="false"
            android:taskAffinity="" />

配置了android:resizeableActivity=”false”

运行后发现如果在分屏界面,会提示“应用不支持分屏”然后全屏显示。

所以这个配置是启用和禁用多窗口显示的,N里面默认为true。

3、start activity adjacent

 public void onStartAdjacentActivity(View view) {
        Log.d(mLogTag, "** starting AdjacentActivity");

        /*
         * Start this activity adjacent to the focused activity (ie. this activity) if possible.
         * Note that this flag is just a hint to the system and may be ignored. For example,
         * if the activity is launched within the same task, it will be launched on top of the
         * previous activity that started the Intent. That's why the Intent.FLAG_ACTIVITY_NEW_TASK
         * flag is specified here in the intent - this will start the activity in a new task.
         */
        Intent intent = new Intent(this, AdjacentActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT | Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
    }
    配置文件
     <activity
            android:name="com.android.multiwindowplayground.activities.AdjacentActivity"
            android:taskAffinity="" />

看效果

在启动新 Activity 时,用户可以提示系统如果可能,应将新 Activity 显示在当前 Activity 旁边。 要执行此操作,可使用标志 Intent.FLAG_ACTIVITY_LAUNCH_TO_ADJACENT。 传递此标志将请求以下行为

  • 如果设备处于分屏模式,系统会尝试在启动系统的 Activity 旁创建新 Activity,这样两个 Activity 将共享屏幕。

    系统并不一定能实现此操作,但如果可以,系统将使两个 Activity 处于相邻的位置。
  • 如果设备不处于分屏模式,则该标志无效。

    并且发现onMultiWindowModeChanged函数执行了

    这个函数的作用是

    Activity 进入或退出多窗口模式时系统将调用此方法。 在 Activity 进入多窗口模式时,系统向该方法传递 true 值,在退出多窗口模式时,则传递 false 值。

    4、start activity that handles configurationchanges

这个主要处理一些配置文件的改变

下面还有两个事件

5、start activity with Minimum size

 <activity
            android:name="com.android.multiwindowplayground.activities.MinimumSizeActivity"
            android:launchMode="singleInstance"
            android:taskAffinity="">
            <layout
                android:defaultHeight="500dp"
                android:defaultWidth="750dp"
                android:gravity="top|end"
                android:minWidth="500dp"
                android:minHeight="500dp" />
        </activity>

主要用来设置一些布局属性

android:defaultWidth :以自由形状模式启动时 Activity 的默认宽度。

android:defaultHeight:以自由形状模式启动时 Activity 的默认高度

android:gravity:以自由形状模式启动时 Activity 的初始位置。请参阅 Gravity 参考资料,了解合适的值设置。

android:minimalHeight、android:minimalWidth:分屏和自由形状模式中 Activity 的最小高度和最小宽度。 如果用户在分屏模式中移动分界线,使 Activity 尺寸低于指定的最小值,系统会将 Activity 裁剪为用户请求的尺寸。

进入自由形状模式的方法:

1). 打开模拟器或者用usb线连接已root了的设备

2). 在cmd命令行中输入adb shell

3). 然后输入su获得root操作权限

4). 输入settings put global enable_freeform_support 1

5). 重启模拟器或设备。

6、start activity with Launch Bounds

 public void onStartLaunchBoundsActivity(View view) {
        Log.d(mLogTag, "** starting LaunchBoundsActivity");

        // Define the bounds in which the Activity will be launched into.
        Rect bounds = new Rect(500, 300, 100, 0);

        // Set the bounds as an activity option.
        ActivityOptions options = ActivityOptions.makeBasic();
        options.setLaunchBounds(bounds);

        // Start the LaunchBoundsActivity with the specified options
        Intent intent = new Intent(this, LaunchBoundsActivity.class);
        startActivity(intent, options.toBundle());

    }

这个和上面第5点差不多 只是在代码中设置新activity的尺寸和屏幕位置。

官方示例给的还是挺全的,

Android 多窗口的更多相关文章

  1. Android 之窗口小部件详解--App Widget

    Android 之窗口小部件详解--App Widget  版本号 说明 作者 日期  1.0  添加App Widge介绍和示例  Sky Wang 2013/06/27        1 App ...

  2. Android 核心分析之十二Android GEWS窗口管理之基本架构原理

    Android GWES之窗口管理之基本构架原理 Android的窗口管理是C/S模式的.Android中的Window是表示Top Level等顶级窗口的概念.DecorView是Window的To ...

  3. Android 之窗口小部件详解(三)  部分转载

    原文地址:http://blog.csdn.net/iefreer/article/details/4626274. (一) 应用程序窗口小部件App Widgets 应用程序窗口小部件(Widget ...

  4. Android 之窗口小部件高级篇--App Widget 之 RemoteViews - 跨到对岸去

    在之前的一篇博文( Android 之窗口小部件详解--App Widge t)中,已经介绍了App Widget的基本用法和简单实例.这篇主要讲解 App Widget 的高级内容,即通过 Remo ...

  5. Android 改变窗口标题栏的布局

    Android改变窗口标题栏的布局  第一种方式 --在XML文件里面引入配置文件作为标题. 第二种方式  --动态的代码加入进去. 第三种方式(网上的): 一. 重点 一般应用的Title都是建立应 ...

  6. Android创建窗口(一)创建应用窗口

    所谓的窗口(Window)就是一个显示在手机屏幕上可视化视图的一片区域.在Android中窗口是一个抽象的概念,每一个Activity就对应着一个窗口,而所有的窗口都是由视图(View)来呈现,而我们 ...

  7. Android 的窗口管理系统 (View, Canvas, WindowManager)

    http://blog.csdn.net/ritterliu/article/details/39295271 From漫天尘沙 在图解Android - Zygote 和 System Server ...

  8. 【Android】窗口机制分析与UI管理系统

    类图关系 在看Android的窗口机制之前,先看看其主要的类图关系以及层级之间的依赖与调用关系 1.window在当前的android系统的中的呈现形式是PhoneWindow (frameworks ...

  9. Android 浮动窗口进阶——画中画,浮动视频(附Demo)

    今天继续上一篇Android顶层窗口.浮动窗口的进阶应用.上一篇主要讲解了WindowManager服务和如何使用WindowManager编写一个顶层窗口.今天主要是讲讲如何在顶层窗口里面播放视频, ...

  10. Android 之窗口小部件高级篇--App Widget 之 RemoteViews

    Android 之窗口小部件高级篇--App Widget 之 RemoteViews 在之前的一篇博文(Android 之窗口小部件详解--App Widget)中,已经介绍了App Widget的 ...

随机推荐

  1. 我是如何在公司项目中使用ESLint来提升代码质量的

    ESLint:你认识我吗 ESLint是一个语法规则和代码风格的检查工具. 和学习所有编程语言一样,想要入门ESLint,首先要去它的官网看看:https://eslint.org/. ESLint的 ...

  2. [LeetCode] Asteroid Collision 行星碰撞

    We are given an array asteroids of integers representing asteroids in a row. For each asteroid, the ...

  3. [LeetCode] Subarray Sum Equals K 子数组和为K

    Given an array of integers and an integer k, you need to find the total number of continuous subarra ...

  4. C语言中关于运算符优先级别

    在一一个表达式中可能有多个不同的运算符结合起来,由于运算符的优先级别不一样,可能会形成得到的结果不同. 优先级从上到下依次递减,最上面具有最高的优先级,逗号操作符具有最低的优先级. 对于相同的优先级, ...

  5. spring源码阅读(2)核心类介绍

    (1).BeanFactory作为一个主接口不继承任何接口,暂且称为一级接口. (2).有3个子接口继承了它,进行功能上的增强.这3个子接口称为二级接口. (3).ConfigurableBeanFa ...

  6. 基于webpack的React项目搭建(二)

    前言 前面我们已经搭建了基础环境,现在将开发环境更完善一些. devtool 在开发的过程,我们会经常调试,so,为了方便我们在chrome中调试源代码,需要更改webpack.config.js,然 ...

  7. [Codeforces]856E - Satellites

    传送门 做法:每个卫星分别用连到左边圆与x轴交点的线的斜率和连到右边交点的线旋转90度的斜率可以表示成一个区间,问题转化成支持加/删区间和询问其中两个区间是否有交以及它们的交是否被其他区间包含.我一开 ...

  8. [BZOJ]4644: 经典傻逼题

    某天我觉得一切题目都是那么不可做,于是百度了一下"傻逼题"-- 题目大意:对于图中的任意一个点集(可以为空或者全集),所有恰好有一个端点在这个点集中的边组成的集合被称为割.一个割的 ...

  9. 【USACO15FEB】审查(黄金)Censoring (Gold)

    题目描述 Farmer John has purchased a subscription to Good Hooveskeeping magazine for his cows, so they h ...

  10. 51Nod 1530 稳定方块

    瓦西亚和皮台亚摆放了m个方块.方块被编号为0到m-1(每个号码出现恰好一次).现在建立一个座标系OX表示地面,OY的方向是竖直向上的.每一方块的左下角有一个座标而且是整点座标. 摆放好的方块一定要是稳 ...