FrameLayout中的Android Scale ImageView

时间:2015-08-26 18:56:19

标签: image imageview scaling

我的应用程序需要在framelayout中进行缩放,移动和旋转的图像视图。所有操作都已成功完成但是动作在imageview边界内工作,而不是在framelayout上。我的xml和java是:

<FrameLayout
        android:id="@+id/square_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="center">

        <ImageView
            android:id="@+id/new_img"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:adjustViewBounds="true"
            android:scaleType="matrix"


            />


    </FrameLayout>


   ImageView imageView = (ImageView) findViewById(R.id.new_img);

@Override
public boolean onTouch(View view, MotionEvent motionEvent) {


    //mScaleFactor gets from scaleGesture
    float scaleImageCenterX = (imageView.getWidth()*mScaleFactor)/2;
    float scaleImageCenterY = (imageView.getHeight()*mScaleFactor)/2;

    mMatrix.reset();
    mMatrix.postScale(mScaleFactor, mScaleFactor);
    mMatrix.postRotate(mRotationDegrees,scaleImageCenterX,scaleImageCenterY);
    mMatrix.postTranslate(mFocusX - scaleImageCenterX, mFocusY - scaleImageCenterY);
    // ImageView view = (ImageView)imageView;
    imageView.setImageMatrix(mMatrix);



    return true;


}

before scaling imageview

after scaling imageview

只有图像缩放(ImageView不缩放)。请给出正确的方向或任何建议的朋友。

0 个答案:

没有答案