Android View Disappearing When Go Outside Of Parent

后端 未结 6 414
甜味超标
甜味超标 2020-12-01 02:38

I have a LinearLayout and ImageView inside this LinearLayout.

There is a translation effect for ImageView.

// v = ImageView    
ObjectAnimator anima         


        
相关标签:
6条回答
  • 2020-12-01 02:58
    try to update camera position as in my case below:
     ValueAnimator lockAnimator = ValueAnimator.ofFloat(1, 0);     // value from 0 to 1
                    lockAnimator.setDuration(500);
                    lockAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                        @Override
                        public void onAnimationUpdate(ValueAnimator pAnimation) {
                            float value = (Float) (pAnimation.getAnimatedValue());
                            if (value < .6 && flipped) {
                                if (preview != null)
                                    mCanvasImage.setImageBitmap(preview);
                                else
                                    mCanvasImage.setImageBitmap(imageBitmap);
                                flipped = false;
                            }
                            if (value > .3 && value < .7) {
                                lyt_rlt_container.setCameraDistance(lyt_rlt_container.getCameraDistance() - 100);
                            } else {
                                lyt_rlt_container.setCameraDistance(lyt_rlt_container.getCameraDistance() + 100);
                            }
                            lyt_rlt_container.setRotationY(180 * value);
    
                        }
                    });
                    lockAnimator.start();
    
    0 讨论(0)
  • 2020-12-01 03:02

    In my case clipChildren did nothing but clipToPadding="false" fixed the problem. Go figure.

    0 讨论(0)
  • 2020-12-01 03:06

    Find the ViewGroup that the ImageView belongs to and apply ViewGroup.setClipChildren(false). By default, the drawing of the children is limited to the bounds of the parent ViewGroup.

    0 讨论(0)
  • 2020-12-01 03:08

    Two attributes exist that may cause this to happen: clipChildren and clipToPadding. You'll need to set clipChildren to false for each parent ViewGroup whose bounds the object will animate out of. You also need to set clipToPadding to the immediate parent (and maybe more, but I haven't seen a case for it yet).

    You can set both attributes in the XML

    android:clipChildren="false"
    android:clipToPadding="false"
    

    or in code

    viewGroup.setClipChildren(false);
    viewGroup.setClipToPadding(false);
    
    0 讨论(0)
  • 2020-12-01 03:13

    Get the view height, then add a percentage of the height to where it will slide to

    public void SlideUp(View view){
         float height = view.getHeight();
    
         TranslateAnimation animate = new TranslateAnimation(0,0,0,0);   
    
         animate.setDuration(500);
         animate.setFillAfter(true);
    
         view.animate().translationY((float)(0-0.62*height)).start(); 
         view.startAnimation(animate);
    }
    
    0 讨论(0)
  • 2020-12-01 03:19

    My implementation. It can probably help somebody:

    Java version:

    public static void setAllParentsClip(View v, boolean enabled) {
        while (v.getParent() != null && v.getParent() instanceof ViewGroup) {
            ViewGroup viewGroup = (ViewGroup) v.getParent();
            viewGroup.setClipChildren(enabled);
            viewGroup.setClipToPadding(enabled);
            v = viewGroup;
        }
    }
    

    call setAllParentsClip(yourView, false); to disable the clipping in all the parents.

    Edited:

    Kotlin's version as an extension function:

    fun View.setAllParentsClip(enabled: Boolean) {
        var parent = parent
        while (parent is ViewGroup) {
            parent.clipChildren = enabled
            parent.clipToPadding = enabled
            parent = parent.parent
        }
    }
    

    Call: yourView.setAllParentsClip(false)

    0 讨论(0)
提交回复
热议问题