android 5.0 支持的z轴实现机制
2015-05-24 13:05
330 查看
android 5.0 要支持 z 轴效果,view 的先后顺序就得随着 z 轴上的位置可以动态的调整,view 先后位置的确定是怎么计算的呢,可以看看
ViewGroup 里面的 buildOrderedChildList 这个方法
该方法核心思想是按照 view 在 z 轴上的距离,使用插入法重新排序,放入新的列表中。
ViewGroup 里面的 buildOrderedChildList 这个方法
[code] /** * Populates (and returns) mPreSortedChildren with a pre-ordered list of the View's children, sorted first by Z, then by child drawing order (if applicable). This list must be cleared after use to avoid leaking child Views. Uses a stable, insertion sort which is commonly O(n) for ViewGroups with very few elevated children. */ ArrayList<View> buildOrderedChildList() { final int count = mChildrenCount; if (count <= 1 || !hasChildWithZ()) return null; if (mPreSortedChildren == null) { mPreSortedChildren = new ArrayList<View>(count); } else { mPreSortedChildren.ensureCapacity(count); } final boolean useCustomOrder = isChildrenDrawingOrderEnabled(); for (int i = 0; i < mChildrenCount; i++) { // add next child (in child order) to end of list int childIndex = useCustomOrder ? getChildDrawingOrder(mChildrenCount, i) : i; View nextChild = mChildren[childIndex]; float currentZ = nextChild.getZ(); // insert ahead of any Views with greater Z int insertIndex = i; while (insertIndex > 0 && mPreSortedChildren.get(insertIndex - 1).getZ() > currentZ) { insertIndex--; } mPreSortedChildren.add(insertIndex, nextChild); } return mPreSortedChildren; }
该方法核心思想是按照 view 在 z 轴上的距离,使用插入法重新排序,放入新的列表中。
相关文章推荐
- Java EE 5.0例程初探 EJB3.0的实现和对AJAX的支持
- 基于rtsp的手机视频点播实现和研究(扩展支持android, ios平台)
- ArcGIS Server 9.3 中AJAX支持两种实现方式:Callback机制和PartialPostback 机制。
- android binder机制实现【zz】
- Android进程间通信--消息机制及IPC机制实现 推荐
- [转Android进程间通信--消息机制及IPC机制实现 ]
- Android 支持多屏幕机制
- Android进程间通信--消息机制及IPC机制实现
- Android 支持多屏幕机制
- Android 支持多屏幕机制
- Google应用在Android上的Push机制以及C2DM框架的底层实现
- Android 电话的反射调用机制实现静默接听电话
- Android 支持多屏幕机制
- Android进程间通信--消息机制及IPC机制实现
- Android 支持多屏幕机制
- Android 支持多屏幕机制
- Android中利用App实现消息推送机制的代码实例
- Android 支持多屏幕机制
- Android 支持多屏幕机制
- Android 支持多屏幕机制