clipChildren is not working

后端 未结 5 1805
傲寒
傲寒 2020-12-30 23:51

In my application i am trying to move images using animation. When i try to animate the image (imageView2 or imageView4) to imageView1

5条回答
  •  爱一瞬间的悲伤
    2020-12-31 00:17

    The idea of @roflharrison is quite good, however, the codes has some problem: Here we disable clipChildren recursively, but when we reached the root view, it's v.getParents() would be null, the method returns immediately, and its ClipChildren attribute won't be disabled.

    What's more, for the following line:

    if (v.getParent() instanceof View)
    

    ?? Shouldn't the parent of the view be a ViewGroup? And shouldn't we disable ViewGroup's clip attributes, not View's? So I change the code to the following, and it worked quite well:

    public void disableClipOnParents(View v) {
        if (v == null) {
            return;
        }
        if (v instanceof ViewGroup) {
            ((ViewGroup) v).setClipChildren(false);
        }
        disableClipOnParents((View) v.getParent());
    }
    

提交回复
热议问题