【问题标题】:Android : ImageButton Width & HeightAndroid : ImageButton 宽度和高度
【发布时间】:2014-09-05 18:24:03
【问题描述】:

我有一个 ImageButton,它有一个来自我添加到名为 imgholder 的 drawble-hdpi 文件夹中的图像的 scr,这个图像宽度 = 96pix 和高度 = 96px

但是当我在其点击事件中检查 ImageButton 的高度和宽度时,我得到 128!

这是为什么呢?额外的来自哪里以及如何解决这个问题,以便 ImageButton 与 src 图像具有相同的宽度。 谢谢

<ImageButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/ibAddImage1"
    android:src="@drawable/imgholder"
    android:layout_above="@+id/tvAddReviseCaption"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:background="@android:color/transparent" />

【问题讨论】:

    标签: java android height width imagebutton


    【解决方案1】:

    “px”将设备更改为设备。 您应该将 dp 用于 layout_width 和 layout_height android:layout_width="96dp" android:layout_height="96dp"

    【讨论】:

    • 我没有硬编码任何宽度或高度,它自己的图像是 96x96 pix。
    • 128 可以是图像的 dp 大小。所以你的图片尺寸可以 (96X96)px = (128X128)dp
    猜你喜欢
    • 1970-01-01
    • 2015-03-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多