我试图将ImageButton
从100%缩放到0%。该部分正在工作,但它似乎也正朝着屏幕的左上角(朝向0,0)移动视图。我不希望我只是想扩展它。为什么这也是翻译的观点?使用不正确坐标的Android缩放动画
的ScaleAnimation实施
if (view.getVisibility() == 0) {
final ScaleAnimation scaleAnimation = new ScaleAnimation(1.0f, 0.0f, 1.0f, 0.0f, Animation.ABSOLUTE, centerX, Animation.ABSOLUTE, centerY);
scaleAnimation.setInterpolator(interpolator);
scaleAnimation.setDuration(5000);
view.startAnimation((Animation)scaleAnimation);
scaleAnimation.setAnimationListener(new Animation.AnimationListener(){
public void onAnimationEnd(Animation animation) {
view.setVisibility(n);
}
public void onAnimationRepeat(Animation animation) {
}
public void onAnimationStart(Animation animation) {
}
});
}
}
的ImageButton
和其父android.support.design.widget.CoordinatorLayout
在XML:
<android.support.design.widget.CoordinatorLayout android:id="@+id/main_content"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<ImageButton
android:id="@+id/buttonToggleResultsWindow0"
android:layout_width="35dp"
android:layout_gravity="top|end"
android:layout_height="35dp"
android:visibility="gone"
android:hint="Hide results window"
android:backgroundTint="@color/accent"
android:src="@drawable/ic_filter_tilt_shift_white_24dp"
android:onClick="toggleResultsWindow"
android:background="@drawable/ripple_circle"
/>
编辑1
如果我改变日ËScaleAnimation
构造这个
final ScaleAnimation scaleAnimation = new ScaleAnimation(1.0f, 0.0f, 1.0f, 0.0f, Animation.RELATIVE_TO_SELF, centerX, Animation.RELATIVE_TO_SELF, centerY);
并设置centerX
至8 centerY
4似乎停留在相同的位置或非常接近相同的位置。这对我来说没有任何意义。什么导致了这种行为?
编辑2
我想通了,是什么原因造成的意见翻译,但我仍然不知道如何解决它。看起来如果我在动画之前的任何时候使用setx()
或setY()
来移动视图,那么它会变得混乱。这是因为动画仍在使用视图的原始位置,而不是新的位置。所以当它翻译视图时,它正在被翻译成原始位置。我怎样才能使ScaleAnimation
使用正确的坐标?
将两者都设置为'Animation.RELATIVE_TO_SELF'且两个值都转换为'0.5f'并没有改变任何东西 – TychoTheTaco