Android 平移动画解决平移后位置不能点击问题

private void setAnimationDown() {
        topViewIsUp = false;
        ImageView iv1 = findViewById(R.id.iv1);
        LinearLayout ll2 = findViewById(R.id.ll2);
        LinearLayout ll3 = findViewById(R.id.ll3);
//创建平移动画
        TranslateAnimation translateAnimation = new TranslateAnimation(0, 0, 0, 200);
        translateAnimation.setDuration(300);
        iv1.startAnimation(translateAnimation);
        ll2.startAnimation(translateAnimation);
        ll3.startAnimation(translateAnimation);
//监听平移后的状态
        translateAnimation.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {

            }

            @Override
            public void onAnimationEnd(Animation animation) {
//在动画结束时,要把平移后的位置设置起来,用设置动画的控件去找他的父控件
//布局里面父控件是什么就选什么(我这里父控件是RelativeLayout,所以使用RelativeLayout.LayoutParams)
//如果你是LinearLayout就设置LinearLayout.LayoutParams
                RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) iv1.getLayoutParams();
                lp.topMargin += 200;
                iv1.setLayoutParams(lp);
//位置设置好以后一定要记得清除动画
                iv1.clearAnimation();
                RelativeLayout.LayoutParams lp2 = (RelativeLayout.LayoutParams) ll2.getLayoutParams();
                lp2.topMargin += 200;
                ll2.setLayoutParams(lp2);
//位置设置好以后一定要记得清除动画
                ll2.clearAnimation();
            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });
    }

你可能感兴趣的:(Android 平移动画解决平移后位置不能点击问题)