我想使用Property Animation来演示流星动画,但失败了。我的演示很简单: 1.创建一个具有启动按钮的MainActivity。 2.单击开始按钮以启动MeteorActivity 3. MeteorActivity具有相对布局内容视图,其中包含位于布局中间/中间的简单星形ImageView。 4.在MeteorActivity的onResume方法中,我启动属性动画以将ImageView的“top”属性从0更改为1000. 问题在于,星星从上边缘向下滑动直到其到达原始位置布局)。它消失了!任何人都可以帮忙吗?为什么ImageView在动画中消失?
MeteorActivity:
public class MeteorActivity extends Activity implements ValueAnimator.AnimatorUpdateListener{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_meteor);
}
@Override
protected void onResume() {
super.onResume();
startMeteor();
}
private void startMeteor() {
ImageView imageView = (ImageView) findViewById(R.id.starImageView);
ObjectAnimator anim = ObjectAnimator.ofInt(imageView, "top", 0, 1000);
anim.setDuration(10000);
anim.addUpdateListener(this);
anim.start();
}
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator){
ImageView imageView = (ImageView) findViewById(R.id.starImageView);
Log.d("ImageView:Height:", Integer.valueOf(imageView.getTop()).toString());
}
}
Layout.xml
<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" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/starImageView"
android:src="@drawable/meteor"
android:layout_centerHorizontal="true"/>
你能分享布局xml代码吗? – 2015-04-02 05:40:34
布局xml补充,谢谢, – iceagle 2015-04-02 06:22:45