[英]TextView is not getting remove by using animation
我知道很多人都问过这种类型的问题,只是看着我的代码和问题。
我正在使用此方法在linearLayout内填充文本视图,并且工作正常。
private void inflateTextView(String name) {
TextView tv = (TextView) getLayoutInflater().inflate(R.layout.category_text_view, null);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
params.setMargins(10, 0, 0, 10);
tv.setText(name);
tv.setLayoutParams(params);
tv.setOnClickListener(this);
category_container.addView(tv);
}
现在我想要的是,当用户单击特定的文本视图时,它会被动画删除,并且删除部分也可以正常工作。 但是,当我删除一个特定的textView时,其他先前膨胀的textViews并没有说明其位置。 使用这种方法,似乎只在绘图部分上起作用,而实际视图并没有被删除。
ObjectAnimator animX = ObjectAnimator.ofFloat(textView, View.SCALE_X, 0f);
ObjectAnimator animY = ObjectAnimator.ofFloat(textView, View.SCALE_Y, 0f);
AnimatorSet animSetXY = new AnimatorSet();
animSetXY.playTogether(animX, animY);
animSetXY.setDuration(500);
animSetXY.start();
但是,当我将旧类与动画侦听器一起使用时,视图突然被删除(当然,它会偏离),但我希望它是平滑的。
if (goAnimation == null) {
goAnimation = new ScaleAnimation(
1f, 0f, // Start and end values for the X axis scaling
1f, 0f, // Start and end values for the Y axis scaling
Animation.RELATIVE_TO_SELF, 0.5f, // Pivot point of X scaling
Animation.RELATIVE_TO_SELF, 0.5f); // Pivot point of Y scaling
goAnimation.setFillAfter(false); // Needed to keep the result of the animation
goAnimation.setDuration(300);
}
textView.startAnimation(goAnimation);
goAnimation.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
textView.setVisibility(View.GONE);
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.