我有一个动画(xml)文件,它将图像视图设置为看起来像电影的片尾:
<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/linear_interpolator" >
<translate
android:duration="10000"
android:fromYDelta="100%p"
android:toYDelta="0%p" />
</set>
如您所见,图像停止&#34;移动&#34;当它全屏显示。还行吧。 我的问题是:当这个IV到达动画的结尾时,如何设置textView(隐藏)可见,所以文本可以在图像上?
java代码:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_final);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
mozart=(ImageView) findViewById(R.id.mozart);
Picasso.with(this).load(R.drawable.amadeus).fit().centerCrop().into(mozart);
read=(TextView) findViewById(R.id.read);
restart=(Button) findViewById(R.id.restart);
restart.setOnClickListener(this);
Animation moz= AnimationUtils.loadAnimation(this, R.anim.animation);
mozart.startAnimation(moz);
read.setVisibility(View.INVISIBLE);
read.setText("Text to appear with other alphaAnimation");
}
@Override
public void onClick(View view) {
if (view == restart) {
allaTurca.stop();
Intent a = new Intent(this, MainActivity.class);
startActivity(a);
this.finish();
}
}
}
有可能吗?我已经尝试了几种方法,但是我无法弄清楚如何在图像准备就绪时告诉程序“接收”#34;文本。获得帮助
答案 0 :(得分:2)
动画启动重复和结束
您必须像这样添加动画侦听器
moz.setAnimationListener(new Animation.AnimationListener(){
@Override
public void onAnimationStart(Animation arg0) {
//Do Something on start
}
@Override
public void onAnimationRepeat(Animation arg0) {
}
@Override
public void onAnimationEnd(Animation arg0) {
}
});
当动画开始时,它将首先通过onStart(这是你可以初始化动画变量的地方)......
然后如果您在动画中重复onAnimationRepeat将被调用。
动画完成后,将调用onAnimationEnd。 (这是您感兴趣的部分)
修改强> 正如评论中所指出的......更好的方法是使用AnimatorListenerAdapter ....谢谢marmor
AnimatorListenerAdapter onEnd = new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator _a) {
DropZone.this.setTranslationY(getHeight() + 2);
DropZone.this.setAlpha(0f);
}
};
找到示例