Android crashes when calling ImageButton
Posted
by Joël
on Stack Overflow
See other posts from Stack Overflow
or by Joël
Published on 2010-04-21T17:23:08Z
Indexed on
2010/04/22
1:33 UTC
Read the original article
Hit count: 506
android
|imagebutton
I have a crash (Application Stopped Unexpectedly) problem with this main.xml is a "HelloWorld" type project (while testing and learning features I need for my app) :
I isolated the ImageButton as an issue, but I can't isolate any of the parameters...
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ImageButton android:id="@+id/picture"
android:layout_width="240dip"
android:layout_height="180dip"
android:layout_gravity="center_horizontal"
android:src="@drawable/icon"
android:adjustViewBounds="true"
android:cropToPadding="true"
android:clickable="true"
android:scaleType="fitCenter" />
</LinearLayout>
icon.png exists in my resources... I can see the preview in the Layout tab, even though the image is not centered on the button, but I read that it was normal.
The code below works fine (as a regular Button). I can also do the same as an ImageView.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<Button android:id="@+id/picture"
android:layout_width="240dip"
android:layout_height="180dip"
android:layout_gravity="center_horizontal" />
</LinearLayout>
I use Eclipse and the AVD, and all my learning is done on 2.1 (SDK level 7). I can't test the app on an actual device yet as I don't have it yet.
Thanks in advance !
© Stack Overflow or respective owner