使用ScaleType矩阵将ImageView中心放置在适当的位置 [英] ImageView Center in position with ScaleType Matrix
本文介绍了使用ScaleType矩阵将ImageView中心放置在适当的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在ImageView中使用缩放效果,因此我需要使用scaletype = matrix.现在,我想将中心位置"设置为ImageView,但无法设置它.
请对此提供帮助.
layout.xml:
I am using Zoom effect with ImageView so I need to use scaletype=matrix. Now, I want to set Center position to ImageView but I am not able to set it.
Please help me regarding this.
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>
推荐答案
放入以下代码行:
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.
这篇关于使用ScaleType矩阵将ImageView中心放置在适当的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文