我有一个需要从底部滑入的ImageView。在那里停留5秒。然后滑出去。我怎么做?没有用户干预。
由于 Rajesh Muthu
答案 0 :(得分:2)
好的,我找到了解决方案。 在名为popup_slider.xml的anim文件夹中创建一个xml
<set xmlns:android="http://schemas.android.com/apk/res/android" android:shareInterpolator="true">
<alpha android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="100" />
<translate android:fromYDelta="100%p" android:toYDelta="0%p" android:startOffset="1000" android:duration="5000" android:zAdjustment="top"/>
<alpha android:fromAlpha="0.99" android:toAlpha="1.0" android:startOffset="6000" android:duration="5000" />
<translate android:fromYDelta="0%p" android:toYDelta="100%p" android:startOffset="11000" android:duration="5000" android:zAdjustment="bottom"/>
<alpha android:fromAlpha="1.0" android:toAlpha="0.0" android:startOffset="16000" android:duration="1000" />
</set>
在Java中实现AnimationListener
public static void popUpAndDownAnimation(View v) {
Animation animation = AnimationUtils.loadAnimation(localContext, R.anim.popup_slider);
animation.setAnimationListener(new Animation.AnimationListener(){
public void onAnimationEnd(Animation arg0) {
popUpAdvertisementView.setVisibility(View.GONE);
}
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
public void onAnimationStart(Animation animation) {
popUpAdvertisementView.setVisibility(View.VISIBLE);
}
});
v.startAnimation(animation);
}
答案 1 :(得分:0)
Android在视图上有简单的动画set of animation classes。您正在寻找的是tween animation。它们提供了一个示例,听起来您可以用XML完成大部分工作。祝你好运^ _ ^