2011-08-11 11 views
9

私はアニメーションでImageViewをスケールダウンしようとしていますが、そうするたびにレイアウト内を左下に移動するように見えます。ImageViewをObjectAnimatorでどのようにスケールダウンしますか?レイアウト内の位置は保持していますか?

before animation

そして、ここではそれがアニメーションの後のように見えるもの:

after animation

が、ImageViewのは、スケールダウンすることは可能ですが、そのトップを持ってここに私はアニメーションの前のスクリーンショットです左上隅はレイアウトの左上隅に残りますか?

// ScaleTestActivity.java 

import android.animation.AnimatorSet; 
import android.animation.ObjectAnimator; 
import android.app.Activity; 
import android.os.Bundle; 
import android.widget.ImageView; 

public class ScaleTestActivity extends Activity { 

    ImageView mImageView; 

    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 

     mImageView = (ImageView)findViewById(R.id.image_view); 
    } 

    @Override 
    protected void onResume() { 
     super.onResume(); 

     ObjectAnimator scaleDownX = ObjectAnimator.ofFloat(mImageView, "scaleX", 0.5f); 
     ObjectAnimator scaleDownY = ObjectAnimator.ofFloat(mImageView, "scaleY", 0.5f); 

     scaleDownX.setDuration(1000); 
     scaleDownY.setDuration(1000); 

     AnimatorSet scaleDown = new AnimatorSet(); 

     scaleDown.play(scaleDownX).with(scaleDownY); 
     scaleDown.start(); 
    } 
} 

レイアウト:

<!-- main.xml --> 
<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 

    <ImageView 
     android:id="@+id/image_view" 
     android:src="@drawable/droid" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" 
     android:layout_alignParentLeft="true" /> 

</RelativeLayout> 

描画可能リソース:

Large Android Logo

答えて

13

あなたが設定しようとするかもしれビューのpivotXここ

は、私が使用していたコードですYを0にピボットさせます。スケーリングはその点から実行されます。私はそれがうまくいくと思います。

+0

これは私が探していたものです。ありがとう! –

関連する問題