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) {
}
});
}
}
XML의 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"
/>
편집 한
전자 ScaleAnimation
이
final ScaleAnimation scaleAnimation = new ScaleAnimation(1.0f, 0.0f, 1.0f, 0.0f, Animation.RELATIVE_TO_SELF, centerX, Animation.RELATIVE_TO_SELF, centerY);
에 생성자와는 8 centerX
을 설정하고 centerY
4 동일한 위치에 머물거나 같은 위치에 매우 가까운 것으로 보인다. 이것은 나에게 어떤 의미가되지 않습니다. 이 문제의 원인은 무엇입니까?
편집 2
I의 의견의 번역을 유발하지만 난 여전히 그것을 해결하는 방법을 잘 모르겠어요 있는지 알아 냈어. 애니메이션 전에 언제든지 setx()
또는 setY()
을 사용하여보기를 이동하는 것처럼 보이면 엉망이됩니다. 이는 애니메이션이 여전히 새로운 뷰가 아닌 뷰의 원래 위치를 사용하기 때문입니다. 따라서 뷰를 변환하면 원래 위치로 변환됩니다. ScaleAnimation
에서 올바른 좌표를 사용하려면 어떻게해야합니까?
'Animation.RELATIVE_TO_SELF'과 피벗 값을 모두'0.5f'로 설정해도 아무 것도 변경되지 않았습니다. – TychoTheTaco