Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
MidoriInu1 opened this issue Jun 23, 2016 · 2 comments

Comments

@MidoriInu1
Copy link
Contributor

如题,考虑可能是子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
Copy link
Owner

misakuo commented Jun 23, 2016

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

misakuo added a commit that referenced this issue Jun 28, 2016
@misakuo
Copy link
Owner

misakuo commented Jun 28, 2016

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants