@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
left = l;
right = r;
top = t;
bottom = b;
Collections.sort(tags, new SortByScale());
for (int i=0;i<tags.size();i++){
Tag tag=tags.get(i);
View child =tag.getChildView();
if (child!=null&&child.getVisibility() != GONE) {
child.setScaleX(tag.getScale());
child.setScaleY(tag.getScale());
child.setAlpha(tag.getAlpha());
int left, top;
left = (int) (centerX + tag.getLoc2DX()) - child.getMeasuredWidth() / 2;
top = (int) (centerY + tag.getLoc2DY()) - child.getMeasuredHeight() / 2;
child.layout(left, top, left + child.getMeasuredWidth(), top + child.getMeasuredHeight());
child.bringToFront();
}
}
SortByScale
class SortByScale implements Comparator {
public int compare(Object o1, Object o2) {
if(o1 instanceof Tag && o2 instanceof Tag){
return ((Tag) o1).getScale()>((Tag) o2).getScale()?1:-1;
}
return 0;
}
}
如题,考虑可能是子View的Z轴排列问题,我自己fork之后做了修改,目前我的解决办法是在
TagCloudView
的onLayout
中用child.bringToFront();
控制Z轴排序。但可能性能上会有问题,希望能有更好的解决方法:) TagCloudViewSortByScale