Why does getScaleY() always returns 1.0? [Android]

倖福魔咒の 提交于 2019-12-25 01:13:51

问题


I have an ImageView that contains an image. This image is getting scaled to fit within the screen because it's too large.

I'm trying to find out how much the image has scaled using getScaleY() and getScaleX(). This should return 1.0 if the image has not been scaled and return some value less than 1.0 if the image is scaled down to fit the view.

Instead, getScaleX() and getScaleY() alsways return 1.0 for me whether the image is scaled down or not.

You can see my XML here:

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

    <ImageView
        android:id="@+id/docImage"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:src="@drawable/dossier_cover"
        android:adjustViewBounds="true"
        android:padding="0dp"
        />

</RelativeLayout>

Does anyone know why this is happening? Or am I better off finding out the scale in a different way?


回答1:


It was because I called getScaleX() before it was drawn. Mystery solved.



来源:https://stackoverflow.com/questions/10279613/why-does-getscaley-always-returns-1-0-android

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