ImageButton not displayed

Discussion in 'Application Development' started by Tollas, May 6, 2010.

  1. Tollas

    Tollas Member
    5

    May 6, 2010
    5
    0
    5
    I'm having troubles getting an image to display as an ImageButton.
    The button is there, but no image is displayed. This is true on another screen that uses the image as well. It's just a blank spot.

    Eclipse layout shows the button image, but the emulator does not. I've used a different @drawable and it works fine in both layout and the emulator. I tried recreating the image (delete, refresh Eclipse, recreate, refresh) but it's still not displayed. I also tried renaming the image, but the problem persists. I've tried the image in other locations and removed the background. Still no image.

    This is the source for the ImageButton
    Code (Text):
    1. <ImageButton
    2.     android:id="@+id/attack_ability_button"
    3.     android:layout_width="52px"
    4.     android:layout_height="52px"
    5.     android:layout_x="15px"
    6.     android:layout_y="72px"
    7.     android:background="@color/clear"
    8.     android:src="@drawable/attack"/>
     

    Advertisement

  2. Tollas

    Tollas Member
    5

    May 6, 2010
    5
    0
    5
    Addition:

    I've also tried the following:

    In strings.xml
    <string name="attack_ability_button_value">@drawable/attack</string>

    In main.xml
    <ImageButton
    android:id="@+id/attack_ability_button"
    android:layout_width="52px"
    android:layout_height="52px"
    android:layout_x="15px"
    android:layout_y="72px"
    android:background="@color/clear"
    android:src="@string/attack_ability_button_value"/>

    Same error. Any other image works, but I can't find anything wrong with the image itself.
    As I've said, I've tried deleting & re-creating (from a new file) the image.
     
  3. Armaced

    Armaced Member
    5

    May 5, 2010
    5
    0
    5
    Remedy consultant
    California
    I am fairly new to Android app dev and I have not yet played with button images, but I was having similar troubles trying to update the icons of some of my practice apps.

    Have you tried moving the .apk file out of your workspace directory, then closing and restarting eclipse? That was the biggest hammer I could find to force the emulator to recognize my changes, and it worked in that instance.

    I hope this helps - good luck.
     
  4. Tollas

    Tollas Member
    5

    May 6, 2010
    5
    0
    5
    The answer I arrived at is to change px to dp.
    While this doesn't tell me WHY the image wasn't displayed, it does fix the problem and makes the images scalable to higher & lower res screens.
     
  5. Lianukink

    Lianukink New Member
    5

    Jun 27, 2011
    1
    0
    5
    I had the same problem. And I resolved it by creating three icons for three resolution low, medium and high, and then put the icons into drawable-ldpi, drawable-mdpi, drawable-hdpi folders. Now my button is customised with required image.
     

Share This Page

Loading...