ImageView - have height match width?

后端 未结 14 2514
长发绾君心
长发绾君心 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:57

    The ImageView "scaleType" function may help you here.

    This code will keep the aspect ratio and position the image at the top:

    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:scaleType="fitStart"
    

    Here is a great post showing the possibilities and appearances from using scaleType.

    ImageView scaleType samples

提交回复
热议问题