简体   繁体   中英

Android : ImageButton Width & Height

I have ImageButton that has a scr from an image I added to the drawble-hdpi folder called imgholder, this image Width = 96pix and Height = 96px

but when I check on the Height and Width for the ImageButton in its click event I get 128!

Why is that? where did the extra came from and how to resolve this so the ImageButton has same width as the src image. Thanks

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

asmgx Plz give code like this as said by the above user :)

<ImageButton
android:layout_width="96dp"
android:layout_height="96dp"
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" />

"px" changes device to device. You should use dp for layout_width and layout_height android:layout_width="96dp" android:layout_height="96dp"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM