【问题标题】:Android: resizing an ImageView in the XMLAndroid:在 XML 中调整 ImageView 的大小
【发布时间】:2011-06-07 15:34:14
【问题描述】:

我的图像太大而无法在屏幕上显示,我希望它在屏幕上相当小。如何通过 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>

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

【问题讨论】:

    标签: android xml imageview


    【解决方案1】:

    例如:

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

    【讨论】:

      【解决方案2】:

      标记,

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

      【讨论】:

      • 注意 fitXY 会扭曲图像的纵横比
      【解决方案3】:

      请试试这个对我有用的

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

      【讨论】:

      • 所以你只是在 8 年后复制粘贴 ameyume 的答案?
      猜你喜欢
      • 1970-01-01
      • 2013-06-27
      • 1970-01-01
      • 2015-07-18
      • 2018-09-26
      • 2018-02-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多