これは最も簡単なことです。ViewPropertyAnimatorを使用して、その中心を中心にImageViewをスケーリングしようとしています。
私は次のレイアウトを持っています:
<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" >
<ImageView
android:id="@+id/imageView"
android:background="@android:color/black"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"/>
<ImageView
android:id="@+id/target"
android:layout_centerInParent="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/crosshair"
/>
次に、次のコードがあります。
// Now we show the burst view
if(mLastBurst != null)
{
((FrameLayout)(mLastBurst.getParent())).removeView(mLastBurst);
mLastBurst.animate().cancel();
mLastBurst.setVisibility(View.GONE);
}
mLastBurst = getLayoutInflater().inflate(R.layout.target, null);
mLastBurst.setX(event.getX()-mLastBurst.getWidth()/2);
mLastBurst.setY(event.getY()-mLastBurst.getHeight()/2);
mLastBurst.setPivotX(50);
mLastBurst.setPivotY(50);
mLastBurst.animate().scaleXBy(10).scaleYBy(10).setDuration(500);
addContentView(mLastBurst,new ViewGroup.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
コードを実行すると、画像の中央付近で画像を拡大縮小するのではなく、画像が左にドリフトします。
私はpivotXとpivotYの値を無駄に試しました。これは単純なはずですが、明らかな何かが欠けていると思います。