【问题标题】:ImageButton image not resizing to smaller sizeImageButton 图像未调整为更小的尺寸
【发布时间】:2016-05-17 16:54:47
【问题描述】:

这是我预期的输出图像:

对于输出图像中显示的每个数字和单词,我有一个图像按钮和单个图像的网格布局。

我为所有这些生成了 9 个补丁图像。现在,当我将其中一个图像用于单个按钮时,将布局宽度和高度设置为包装内容,它显示的太大了,如图所示:(第一个使用“src”属性,第二个使用 ImageButton 的“background”属性.)

但是当我指定一些默认的高度和宽度值(例如 50 dp)时,图像变得太小,甚至看不到数字,如下所示。

布局代码为

    <GridLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:id="@+id/numberGrid"
    android:layout_below="@+id/amountTextView"
    android:layout_gravity="center"
    android:layout_marginTop="9dp"
    android:layout_marginLeft="75dp"
    android:columnCount="3"
    android:rowCount="5"
    >
    <ImageButton android:text="1" />
    <ImageButton android:text="2" />
    <ImageButton android:text="3" />
    <ImageButton android:text="4" />
    <ImageButton android:text="5" />
    <ImageButton android:text="6" />
    <ImageButton android:text="7" />
    <ImageButton android:text="8" />
    <ImageButton android:text="9" />
    <ImageButton android:text="0" 
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:scaleType="center"
     android:src="@drawable/img_btn_0"
     />
    <ImageButton android:text="." />
    <ImageButton android:text="DEL" />
    <ImageButton android:text="CLEAR"
        android:layout_columnSpan="2"
        />
    <ImageButton android:text="OK" />
</GridLayout>

【问题讨论】:

    标签: android android-layout button android-imagebutton


    【解决方案1】:

    尝试在 dp 中指定一些高度和宽度,并将缩放类型设置为“centerCrop”而不是“center”。

    <ImageButton
        android:layout_width="30dp"
        android:layout_height="30dp"
        android:src="@drawable/img_btn_0"
        android:scaleType="centerCrop"/>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-06-25
      • 2020-11-16
      • 2021-05-07
      • 2014-04-23
      • 1970-01-01
      • 1970-01-01
      • 2012-12-16
      • 1970-01-01
      相关资源
      最近更新 更多