【面试总结】Android-开发者值得深入思考的几个面试问答分享

final View nextChild = mChildren[childIndex];
final 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;
}

它里面是通过一个getAndVerifyPreorderedIndex方法来获取对应的子VIew索引,这个方法要传进去一个叫customOrder的boolean。

这个customOrder,看名字可以知道,是自定义顺序的意思,如果它为true的话,接着会通过getChildDrawingOrder(int childCount, int i)方法来获取对应的索引,而且,这个方法是protected的,所以我们可以通过重写这个方法并根据参数"i"来决定返回哪一个View所对应的索引,从而改变分发的顺序。

protected int getChildDrawingOrder(int childCount, int i) {
return i;
}

那这个customOrder,什么时候为true呢?

在buildOrderedChildList方法里可以看到这么一句:

final boolean customOrder = isChildrenDrawingOrderEnabled();

emmmm,也就是说,如果要自定义这个顺序的话,还需要调用setChildrenDrawingOrderEnabled(true)来开启。

重新捋一捋流程:

1. setChildrenDrawingOrderEnabled(true)来开启自定义顺序;
2. 重写getChildDrawingOrder方法来决定什么时候要返回哪个子View;

###2. AppCompatTextView 与 TextView 有什么区别?

1. compat库是如何将TextView替换为AppCompatTextVew的?
2. 为什么要进行替换?
3.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值