我有个按钮。在点击按钮,我动画的TextView。
在动画时,单击不适用于文本视图。
buttonclick.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final Animation animation = new TranslateAnimation(
Animation.RELATIVE_TO_SELF, 1.0f,
Animation.RELATIVE_TO_SELF, 10.0f,
Animation.RELATIVE_TO_SELF, 1.0f,
Animation.RELATIVE_TO_SELF, 10.0f);
animation.setDuration(100000);
textView.startAnimation(animation);
}
});
textView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(MainActivity.this,"Click",Toast.LENGTH_SHORT).show();
}
});
发布于 2017-04-24 11:20:27
Animation
只是充满活力的观点,而不是改变,这是一种幻觉.您使用的是TranslateAnimation
,所以您正在移动视图的“外观”,而不是视图本身。首先,您可以使用setFillAfter(true)
方法,然后在动画结束后可以单击View
(但是您的anim是长/无限的.)。
考虑使用Animator
代替,它正在更改视图的“参数”(在您的实际位置)与每个帧的anim。
ObjectAnimator animX = ObjectAnimator.ofFloat(textView, "x", newx);
ObjectAnimator animY = ObjectAnimator.ofFloat(textView, "y", newy);
AnimatorSet animSetXY = new AnimatorSet();
animSetXY.playTogether(animX, animY);
animSetXY.start();
发布于 2017-04-24 11:40:51
尝尝这个
PropertyValuesHolder x = PropertyValuesHolder.ofFloat("x", 50f);
PropertyValuesHolder y = PropertyValuesHolder.ofFloat("y", 100f);
ObjectAnimator.ofPropertyValuesHolder(mTextView, x, y).start();
这样,你可以动画整个视图对象--不仅仅是内容。
https://stackoverflow.com/questions/43586496
复制相似问题