Android:在XML中调整imageview的大小

时间:2011-06-07 15:34:14

标签: android xml imageview

我的图片太大而无法放在屏幕上,我希望它在屏幕上相当小。如何通过XML更改图像的大小?

我试过了:

<ImageView
android:id="@+id/image"
android:layout_width = "100dp"
android:layout_height= "100dp"
android:scaleType="center"
android:layout_gravity="center_horizontal|bottom"
android:src="@drawable/dashboard_rpm_bottom"
>
</ImageView>

但是图片没有调整大小......它会被裁剪掉。有什么想法吗?

3 个答案:

答案 0 :(得分:119)

例如:

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

添加媒体资源android:scaleType="fitCenter"android:adjustViewBounds="true"

答案 1 :(得分:32)

标记,

我相信你想使用android:scaleType="fitXY"

答案 2 :(得分:1)

请尝试以下一项对我有用

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