Android多窗口分屏(原生方法)


事实上KitKat已经可以实现多窗口分屏,只是功能不全,Google并没有把这个功能提供给用户。

使用am stack boxes可以查看当前系统存在的Activity Stack:

1 am
stack boxes

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来进行分屏显示了:

1 am
stack create 2 1 4 0.5

效果图如下(上半屏为日历应用,下半屏为时钟应用):

Screenshot_2014-10-09-11-18-23
使用上面的命令你可以控制两个APP的相对位置,各自的大小等等。。。具体参数说明如下:


Syntax:

am stack create <int1> <int2> <int3> <float1>

  • <int1>: TASK_ID – the id for the existing task that you want a separate stack for.
  • <int2>: RELATIVE_STACK_BOX_ID – an existing stack id. The postion of the new stack will be relative to this one.
  • <int3>: POSITION – the relative position of the stack. Could be any one of these values:
    • 0: before relative stack (depends on RTL/LTR configuration)
    • 1: after relative stack (depends on RTL/LTR configuration)
    • 2: to left of relative stack
    • 3: to right of relative stack
    • 4: above relative stack
    • 5: below relative stack
    • 6: displayed on a higher layer than the relative stack (unused)
    • 7: displayed on a lower layer than the relative stack (unused)
  • <float1>: WEIGHT – a number between 0.2 – 0.8 inclusive

再次运行am stack boxes来查看一下究竟发生了什么:

1 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的值给出了他们各自的显示区域坐标。


注意!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。



 
粤ICP备14056181号  © 2014-2020 ITdaan.com