ImageView - have height match width?

后端 未结 14 2451
长发绾君心
长发绾君心 2020-12-02 05:17

I have an imageview. I want its width to be fill_parent. I want its height to be whatever the width ends up being. For example:



        
14条回答
  •  失恋的感觉
    2020-12-02 06:06

    Here's how I solved that problem:

    int pHeight =  picture.getHeight();
    int pWidth = picture.getWidth();
    int vWidth = preview.getWidth();
    preview.getLayoutParams().height = (int)(vWidth*((double)pHeight/pWidth));
    

    preview - imageView with width setted to "match_parent" and scaleType to "cropCenter"

    picture - Bitmap object to set in imageView src.

    That's works pretty well for me.

提交回复
热议问题