ImageButton
を100%から0%に拡大しようとしています。その部分は機能していますが、ビューを画面の左上隅に向かって動かしているようにも見えます(0、0に向かって)。私はただそれを拡大したいとは思っていません。なぜこれもビューを翻訳していますか?不正確な座標を使用しているAndroidスケールアニメーション
ScaleAnimation実装XMLで
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
:
<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
私は目を変更した場合この
final ScaleAnimation scaleAnimation = new ScaleAnimation(1.0f, 0.0f, 1.0f, 0.0f, Animation.RELATIVE_TO_SELF, centerX, Animation.RELATIVE_TO_SELF, centerY);
に電子ScaleAnimation
コンストラクタそして、同じ位置にとどまるように見えるか、同じ位置に非常に近い4に8とcenterY
にcenterX
を設定します。これは私には意味をなさない。この現象の原因は何ですか?
編集2
私は、ビューの翻訳を引き起こしているものを考え出したが、私はまだそれを修正するかどうかはわかりません。アニメーションの前にいつでもsetx()
またはsetY()
を使用してビューを移動すると、それはうんざりするようです。これは、アニメーションがまだ新しいビューではなく、ビューの元の位置を使用しているためです。したがって、ビューを平行移動すると、元の位置に向かって移動しています。 ScaleAnimation
に正しい座標を使用させるにはどうすればよいですか?
'Animation.RELATIVE_TO_SELF'と両方のピボット値を両方とも '0.5f'に設定しても何も変更されませんでした – TychoTheTaco