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