Android 多窗口
来源:互联网 发布:苹果音乐变音软件 编辑:程序博客网 时间:2024/06/18 01:13
随着手机屏幕越来越大,单手操作手机越来越难,所以一些大厂早就开始研究多窗口,如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 多窗口
- Android 多窗口详解
- Android多窗口支持
- Android 多窗口实现
- android浏览器研究-多窗口
- Android N 多窗口支持
- Android N 多窗口支持
- Android 7.0 多窗口支持
- android 7.0 多窗口支持
- android N - 多窗口支持
- Android 7.0 多窗口模式
- Android N多窗口支持
- Android N 多窗口模式
- Android Browser学习六 多窗口: NavScreen 切换窗口
- Android Browser学习六 多窗口: NavScreen 切换窗口
- 【Android】窗口构成 应用窗口+系统窗口
- Tieto公司Android多窗口解决方案展示
- Tieto公司Android多窗口解决方案展示
- Mac SecureCRT 8.0.2破解
- 移动端开发基本知识之touch.js,FastClick.js源码分析
- Android开发之内存优化问题
- C++ 中的位操作
- Leetcode-91. Decode Ways
- Android 多窗口
- LINUX linux下的时间函数 我们在编程中可能会经常用到时间,比如取得系统的时间(获取系统的
- SDNU 1093.DNA排序 稳定排序(基数排序)
- 使用Gradle管理你的Android Studio工程
- android实现全屏
- Java关于中质数
- app由于未按照iCoud数据储存的准则被拒解决办法
- NetStat应用详解
- mac 装oh my zsh