ImageView - have height match width?

后端 未结 14 2490
长发绾君心
长发绾君心 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 05:56

    To set your ImageView equal to half the screen, you need to add the following to your XML for the ImageView:

    
    

    To then set the height equal to this width, you need to do it in code. In the getView method of your GridView adapter, set the ImageView height equal to its measured width:

    mImageView.getLayoutParams().height = mImageView.getMeasuredWidth();
    

提交回复
热议问题