【问题标题】:Android: layout_width and height crop my imageAndroid:layout_width 和 height 裁剪我的图像
【发布时间】:2013-11-14 11:35:23
【问题描述】:

我有这个我定义的小布局插入到我的应用程序的每个页面中:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<ImageButton
    android:id="@+id/button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    android:layout_marginRight="10dp"
    android:background="@null"
    android:src="@drawable/sa_info"
    android:layout_alignParentRight="true"/>

我有 118x118 的 sa_info.png,但我希望它在屏幕上看起来更小。如果我尝试将 imagebutton 的宽度和高度设置为所需的大小(比如说 48dp),则在我运行应用程序时生成的图像将被裁剪到中心:

所以我必须获得所需结果的唯一方法是将图像本身缩放到所需的分辨率。 我做错了什么,有更好的方法吗?

【问题讨论】:

    标签: android layout imagebutton


    【解决方案1】:

    尝试添加

    android:scaleType="fitCenter" -> http://developer.android.com/reference/android/widget/ImageView.ScaleType.html

    android:adjustViewBounds="true" -> 如果您希望 ImageView 调整其边界以保持其可绘制对象的纵横比,请将此设置为 true。

    【讨论】:

      猜你喜欢
      • 2016-12-03
      • 2017-05-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-23
      • 2023-04-02
      相关资源
      最近更新 更多