Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid scale imageview around its center
    text
    copied!<p>This should be the simplest thing. I'm trying to use a ViewPropertyAnimator to scale an ImageView around its center. </p> <p>I've got the following layout:</p> <pre><code>&lt;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" &gt; &lt;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"/&gt; &lt;ImageView android:id="@+id/target" android:layout_centerInParent="true" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/crosshair" /&gt; </code></pre> <p></p> <p>Then I have the following code:</p> <pre><code>// 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)); </code></pre> <p>When I run the code all that happens is that rather than scaling the image around the center of the image, the image drifts over to the left.</p> <p>I've played with the pivotX and pivotY values to no avail. This should be simple and I guess I'm missing something obvious.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload