我試圖將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