Android 文本视图仍被单击,但已设置动画以隐藏
我有一个Android 文本视图仍被单击,但已设置动画以隐藏,android,android-layout,animation,android-animation,Android,Android Layout,Animation,Android Animation,我有一个文本视图,它的动画可以在点击时滑出。现在,当我再次单击TextView布局所在的区域时,单击事件仍然会被触发,就好像TextView仍然存在一样。我希望TextView在动画中隐藏后,其行为就像不存在一样 下面是我的动画文件 res/anim/slide_out.xml 有人能提出解决这个问题的办法吗 谢谢 Ammar您可以实现动画。AnimationListener,当调用onAnimationEnd时,您可以根据@blackbelt建议将文本视图的可见性更改为gone,我在活动中进行
文本视图
,它的动画可以在点击时滑出。现在,当我再次单击TextView
布局所在的区域时,单击事件仍然会被触发,就好像TextView
仍然存在一样。我希望TextView
在动画中隐藏后,其行为就像不存在一样
下面是我的动画文件
res/anim/slide_out.xml
有人能提出解决这个问题的办法吗
谢谢
Ammar您可以实现
动画。AnimationListener
,当调用onAnimationEnd
时,您可以根据@blackbelt建议将文本视图的可见性更改为gone,我在活动
中进行了更新
animSlideOut.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) { }
@Override
public void onAnimationEnd(Animation animation) {
animTV.setVisibility( View.GONE );
}
@Override
public void onAnimationRepeat(Animation animation) { }
});
@blackbelt解决方案有一定的帮助。为了使它完全工作,我必须更新slide_out.xml
,将android:fillAfter
属性设置为false
好。此更新后,单击TextView
不会触发。但还有另一个问题。在我的实际布局中,我在动画TextView
覆盖的下方有按钮。现在,尽管动画的TextView
不再可见,但那些按钮仍然无法正常工作,好像上面有什么东西。有什么想法吗?可能你忘了在按钮的实例上调用setOnClickListener,没有。问题在于android:fillAfter
。检查答案。谢谢你的贡献。
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true">
<scale
android:duration="500"
android:fromXScale="1.0"
android:fromYScale="0.0"
android:interpolator="@android:anim/linear_interpolator"
android:toXScale="1.0"
android:toYScale="1.0" />
</set>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<TextView
android:id="@+id/anim_tv"
android:layout_alignParentTop="true"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:text="@string/hello_world"
android:gravity="center"
android:background="#8800ff00"/>
</RelativeLayout>
public class MainActivity extends Activity {
TextView animTV;
Animation animSlideIn;
Animation animSlideOut;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
animTV = (TextView) findViewById(R.id.anim_tv);
animTV.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
hide();
}
});
// load the animation
animSlideIn = AnimationUtils.loadAnimation(this, R.anim.slide_in);
animSlideOut = AnimationUtils.loadAnimation(this, R.anim.slide_out);
show();
}
private void show() {
animTV.startAnimation(animSlideIn);
}
private void hide() {
animTV.startAnimation(animSlideOut);
}
}
animSlideOut.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) { }
@Override
public void onAnimationEnd(Animation animation) {
animTV.setVisibility( View.GONE );
}
@Override
public void onAnimationRepeat(Animation animation) { }
});