ImageView Center与ScaleType Matrix的位置

Jee*_*mar 2 xml android scale android-layout

我正在使用ImageView的Zoom效果,所以我需要使用scaletype = matrix.现在,我想将中心位置设置为ImageView,但我无法设置它.

请帮我解决这个问题.

layout.xml:

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

    <ImageView
        android:id="@+id/imgImage"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:contentDescription="@string/imgdesc"
        android:scaleType="matrix"
        android:src="@drawable/ic_answer" />

</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

Far*_*uzi 6

放下以下代码行:

RectF drawableRect = new RectF(0, 0, image_width, image_height);
RectF viewRect = new RectF(0, 0, screen_width, screen_height);
matrix.setRectToRect(drawableRect, viewRect, Matrix.ScaleToFit.CENTER);
Run Code Online (Sandbox Code Playgroud)

希望这会帮助你.