我有一个崩溃(应用程序意外停止)问题,这个 main.xml 是一个“HelloWorld”类型的项目(在测试和学习我的应用程序所需的功能时):
我将 ImageButton 隔离为一个问题,但我无法隔离任何参数...
<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 存在于我的资源中... 我可以在“布局”选项卡中看到预览,即使图像没有在按钮上居中,但我读到它是正常的。
下面的代码工作正常(作为一个普通的按钮)。我也可以像 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>
我使用 Eclipse 和 AVD,我所有的学习都是在 2.1(SDK 级别 7)上完成的。 我还不能在实际设备上测试该应用程序,因为我还没有。
提前致谢!
最佳答案
哦麻烦了!! 当我试图为按钮声明事件时,这似乎是我的 MyApp.java 中的 java 错误。结案。对不起。
关于Android 在调用 ImageButton 时崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2685106/