Android image view matrix scale + translate

后端 未结 4 1982
执笔经年
执笔经年 2020-11-28 04:52

I am trying to manually get an image inside an imageview centered and fitting the screen. I need to do it with a matrix (I will later dynamically change the matrix transform

4条回答
  •  野性不改
    2020-11-28 05:30

    Or using

        m.postScale(minScale, minScale); //keep aspect ratio
    
        float tx = (getWidth() - bitmap1.getWidth()* scale) * 0.5f ;
        float ty = (getHeight() - bitmap1.getHeight()* scale) * 0.5f ;
    
        matrix.postTranslate(tx, ty );
    

    where getWidth is the width of your imageView. Works perfectly for me

提交回复
热议问题