Tuesday, April 5, 2011

android: how to add an image button?

I am trying to replace my previous ugly text button with an imagebutton. However, after changing the XML file with the following ImageButton code, my application won't even start. Why?

<ImageButton 
android:layout_height="fill_parent"
     android:id="@+id/refresh"
android:src="@drawable/refresh"              
 /> 
From stackoverflow
  • It turned out that I forgot the layout_width attribute. It works now.

    <ImageButton 
            android:layout_height="fill_parent"
            android:id="@+id/refresh"
            android:src="@drawable/refresh"     
            android:layout_width="wrap_content"      
        /> 
    
  • specify the layout width..

    android:layout_width="wrap_content/*some value ex:50dp*/" 
    

0 comments:

Post a Comment