2
這應該是最簡單的事情。我正在嘗試使用ViewPropertyAnimator來圍繞其中心縮放ImageView。Android縮放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的值無濟於事。這應該很簡單,我想我錯過了一些明顯的東西。
我也試過了。沒有快樂。 – Lee
當您詢問寬度和高度時,尺寸是否已知?與其他視圖相比,內容視圖可能會有所不同。嘗試使用另一個容器。 –