Android: resizing imageview in XML

后端 未结 3 768
無奈伤痛
無奈伤痛 2020-12-13 04:42

I have an image that is too big to fit on the screen, i want it fairly small on screen. How do i change the size of the image through XML?

i tried:

         


        
相关标签:
3条回答
  • 2020-12-13 04:44

    Please try this one works for me:

    <ImageView android:id="@+id/image_view"     
      android:layout_width="wrap_content"  
      android:layout_height="wrap_content"  
      android:adjustViewBounds="true"  
      android:maxWidth="60dp" 
      android:layout_gravity="center" 
      android:maxHeight="60dp"  
      android:scaleType="fitCenter"  
      android:src="@drawable/icon"  
      /> 
    
    0 讨论(0)
  • 2020-12-13 04:50

    Mark,

    I believe you want to use android:scaleType="fitXY".

    0 讨论(0)
  • 2020-12-13 05:07

    for example:

    <ImageView android:id="@+id/image_view"     
      android:layout_width="wrap_content"  
      android:layout_height="wrap_content"  
      android:adjustViewBounds="true"  
      android:maxWidth="42dp"  
      android:maxHeight="42dp"  
      android:scaleType="fitCenter"  
      android:layout_marginLeft="3dp"  
      android:src="@drawable/icon"  
      /> 
    

    Add property android:scaleType="fitCenter" and android:adjustViewBounds="true".

    0 讨论(0)
提交回复
热议问题