事实上KitKat已经可以实现多窗口分屏,只是功能不全,Google并没有把这个功能提供给用户。
使用am stack boxes可以查看当前系统存在的Activity Stack:
output:
Box id=1 weight=0.0 vertical=false bounds=[0,38][800,1208] Stack= Stack id=1 bounds=[0,38][800,1208] taskId=2: com.android.calendar/com.android.calendar.AllInOneActivity taskId=3: com.android.deskclock/com.android.deskclock.DeskClock Box id=0 weight=0.0 vertical=false bounds=[0,38][800,1208] Stack= Stack id=0 bounds=[0,38][800,1208] taskId=1: net.lnmcc.launcher/net.lnmcc.launcher.Launcher
从上面的输出我们看到当前有两个Stack,id分别为0和1。在Stack 1中存在了两个Task,这两个Task分别是Calender和DeskClock应用。而Launcher则是在Stack 0中。实际上,你会发现Launcher始终独占Stack 0。Android有如下规则:
- HOME stack: This is the stack with id = 0. This stack is used by the Launcher activities. When several users run Lanchers on one device, they will all belong to this stack. Other than that, systemui activities are also launched in it.
- Applications stack: The id for this stack could be any number. All activities that are neither Launcher apps or systemui activities are run here (for all users).
得到了上面关于Stack和Task的信息后就可以按需要使用am stack create来进行分屏显示了:
效果图如下(上半屏为日历应用,下半屏为时钟应用):
使用上面的命令你可以控制两个APP的相对位置,各自的大小等等。。。具体参数说明如下:
Syntax:am stack create <int1> <int2> <int3> <float1>
|
再次运行am stack boxes来查看一下究竟发生了什么:
output:
Box id=1 weight=0.5 vertical=true bounds=[0,38][800,1208] First child= Box id=2 weight=0.0 vertical=false bounds=[0,38][800,623] Stack= Stack id=2 bounds=[0,38][800,623] taskId=2: com.android.calendar/com.android.calendar.AllInOneActivity Second child= Box id=3 weight=0.0 vertical=false bounds=[0,623][800,1208] Stack= Stack id=1 bounds=[0,623][800,1208] taskId=3: com.android.deskclock/com.android.deskclock.DeskClock Box id=0 weight=0.0 vertical=false bounds=[0,38][800,1208] Stack= Stack id=0 bounds=[0,38][800,1208] taskId=1: net.lnmcc.launcher/net.lnmcc.launcher.Launcher
我们看到Box 1中有了2个子Box,分别用来存放Calendar和DeskClock,并且bounds的值给出了他们各自的显示区域坐标。