2016-07-30 3 views
1

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에서 올바른 좌표를 사용하려면 어떻게해야합니까?

답변

0

pivotXType 및 pivotYType을 사용하려고 시도하면 Animation.RELATIVE_TO_SELF입니다.

+0

'Animation.RELATIVE_TO_SELF'과 피벗 값을 모두'0.5f'로 설정해도 아무 것도 변경되지 않았습니다. – TychoTheTaco

0

pivotXType 및 pivotYType을 사용하려고 시도하면 Animation.RELATIVE_TO_SELF입니다. 그것은 작동하고 내 MainActivity.class

public class MainActivity extends AppCompatActivity { 
    private ImageView imageView; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

     imageView = (ImageView) findViewById(R.id.imageView); 
     animationImageView(); 
    } 

    private void animationImageView() { 
     if (imageView.getVisibility() == View.VISIBLE) { 
      final ScaleAnimation scaleAnimation = new ScaleAnimation(
        1.0f, 0.0f, 1.0f, 0.0f, 
        Animation.RELATIVE_TO_SELF, 0.5f, 
        Animation.RELATIVE_TO_SELF, 0.5f); 
      scaleAnimation.setDuration(5000); 
      imageView.startAnimation(scaleAnimation); 
     } 
    } 
} 

에서 내 activity_main.xml

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#ff0000" 
    tools:context="com.sonnv1368.animationscale.MainActivity"> 

    <ImageView 
     android:id="@+id/imageView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@mipmap/ic_launcher" /> 
</RelativeLayout> 

에서

, 그것은 이미지 뷰의 중심에 확장됩니다.

관련 문제