开发者

Android: resizing an ImageView in the XML

开发者 https://www.devze.com 2023-03-12 01:43 出处:网络
I have an image that is too big to fit on the screen, and I want it fairly small on screen. How do I change the size of the image through XML?

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

I tried:

<ImageView
android:id="@+id/image"
android:layout_width = "100dp"
android:layout_height= "100dp"
android:scaleType="center"
android:layout_grav开发者_开发百科ity="center_horizontal|bottom"
android:src="@drawable/dashboard_rpm_bottom"
>
</ImageView>

But the image isn't resized... it gets cropped. Any ideas?


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".


Mark,

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


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

精彩评论

暂无评论...
验证码 换一张
取 消