我有一张很长的照片。
我想循环从左向右移动它的动画。
以下是视频:http://youtu.be/OvXY6-US-MQ
请看一下"城市线"图像动画(底部一个)。 问题是动画结束时的自由空间。如何让它真的无限?
以下是我在视频中所做的工作:
ivCity = (ImageView) findViewById(R.id.city);
ViewTreeObserver cityObserver = ivCity.getViewTreeObserver();
cityObserver.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
public boolean onPreDraw() {
Log.d(TAG, "ANIMATION PRE DRAW");
// Remove after the first run so it doesn't fire forever
ivCity.getViewTreeObserver().removeOnPreDrawListener(this);
cityWidth = ivCity.getMeasuredWidth();
Animation _translateAnimation = new TranslateAnimation(Animation.ABSOLUTE, getScreenWidth(), Animation.ABSOLUTE, -cityWidth + getScreenWidth(), Animation.ABSOLUTE, 0f, Animation.ABSOLUTE, 0f);
//Animation _translateAnimation = new TranslateAnimation(Animation.ABSOLUTE, getScreenWidth() - cityWidth, Animation.ABSOLUTE, 1.0f, Animation.ABSOLUTE, 0f, Animation.ABSOLUTE, 0f);
_translateAnimation.setDuration(10000);
_translateAnimation.setStartOffset(0);
_translateAnimation.setRepeatCount(Animation.INFINITE);
_translateAnimation.setRepeatMode(Animation.RESTART);
_translateAnimation.setInterpolator(new LinearInterpolator());
_translateAnimation.setFillAfter(true);
ivCity.startAnimation(_translateAnimation);
return true;
}
});
布局是:
<AbsoluteLayout
android:id="@+id/city_layout"
android:layout_marginBottom="15dp"
android:layout_above="@id/btn_settings"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/city"
android:scaleType="center"
android:layout_width="1657.5dp"
android:layout_height="wrap_content"
android:src="@drawable/city"/>
</AbsoluteLayout>