misakuo / 3dTagCloudAndroid

Tagcloud component for android
MIT License
1.65k stars 291 forks source link

当为子View设置背景色后,旋转至后方的子View无法被前方子View遮挡 #8

Closed MidoriInu1 closed 8 years ago

MidoriInu1 commented 8 years ago

如题,考虑可能是子View的Z轴排列问题,我自己fork之后做了修改,目前我的解决办法是在TagCloudViewonLayout中用child.bringToFront();控制Z轴排序。但可能性能上会有问题,希望能有更好的解决方法:) TagCloudView

@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;
        }
    }
misakuo commented 8 years ago

诚然,现在所有的tag都绘制在同一个layer上,如你这样依据scale为tag分层是一个不错的思路,提交一个pull request吧~

misakuo commented 8 years ago

Using compile 'com.moxun:tagcloudlib:1.2.0' instead the old library