ImageView Center in position with ScaleType Matrix

假如想象 提交于 2019-12-04 17:03:50

Put the following lines of code:

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);

Hope this will help you.

try this to your ImageView

  android:layout_centerInParent="true"

try below code:

android:scaleType="centerInside"

or

android:scaleType="fitCenter"

or

android:scaleType="centerCrop"

Under android:scaleType="matrix" circumstance, the only way I found is to use Matrix to set ImageView position, use the following code:

Matrix matrix = new Matrix();
matrix.postTranslate(screen_width/2, screen_height/2);
imageView.setImageMatrix(matrix);
user5872046

I had the sameproblem. Eventually I Gave up for using Matrix and replaced it with this:

android.view.ViewGroup.LayoutParams params = imageView.getLayoutParams();
params.height = desiredHeight;
params.width = desiredWid;
imageView.setLayoutParams(params);

try this,

<?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="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:scaleType="matrix"
        android:src="@drawable/ic_launcher" />

</RelativeLayout>

this may help you

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!