【问题标题】:Android crashes when calling ImageButton调用 ImageButton 时 Android 崩溃
【发布时间】:2010-04-21 17:23:08
【问题描述】:

我的 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)上完成的。 由于我还没有它,所以我还不能在实际设备上测试该应用程序。

提前致谢!

【问题讨论】:

  • 您需要从 Eclipse 的 LogCat 视图中发布 Java 堆栈跟踪。

标签: android imagebutton


【解决方案1】:

哦,麻烦! 当我试图为按钮声明事件时,这似乎是我的 MyApp.java 中的一个 java 错误。结案。对不起。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-04-08
    • 1970-01-01
    • 2016-07-26
    • 2023-04-08
    • 1970-01-01
    • 2013-03-20
    • 2013-05-06
    • 1970-01-01
    相关资源
    最近更新 更多