Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/211.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 图像按钮ID冲突?_Android_Imagebutton - Fatal编程技术网

Android 图像按钮ID冲突?

Android 图像按钮ID冲突?,android,imagebutton,Android,Imagebutton,我的应用程序在使用按钮时可以工作,但当我尝试使用图像按钮时,会出现运行时异常“无法启动活动……”ClassCastException:android:widget:button 我在java文件中按ID设置按钮,如下所示 btn=(按钮)findViewById(R.id.Button) 这是xml中的ImageButton <ImageButton android:id="@+id/button" android:layout_width="wrap_content"

我的应用程序在使用按钮时可以工作,但当我尝试使用图像按钮时,会出现运行时异常“无法启动活动……”ClassCastException:android:widget:button

我在java文件中按ID设置按钮,如下所示

btn=(按钮)findViewById(R.id.Button)

这是xml中的ImageButton

<ImageButton
    android:id="@+id/button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    android:text="@string/hello_world" 
    android:adjustViewBounds="true"
    android:src="@drawable/ball"
android:scaleType="centerCrop"/>

我的同事试图清理项目,但没有成功。我遗漏了什么

救命啊

提前谢谢


Don

图像按钮是而不是按钮。这意味着您不能将一个按钮投射到另一个时段。


感谢Android开发者提供了这种清晰的逻辑。

正确的代码是:
btn=(ImageButton)findViewById(R.id.button)

来自同一个有趣的类别-按钮扩展了文本视图。这就是为什么ImageButton不能扩展按钮-因为文本视图没有文本。对不起,我有点新手!我如何用不会扭曲图像比例的图像制作按钮?按钮不工作!-用户2088429对不起,我有点新手!我如何制作按钮n对于不会扭曲图像比例的图像??按钮不起作用!按钮具有背景功能:除此之外,它还具有根据文本确定图像方向的功能。问题是它的方向和大小要适合文本。我希望它适合图像。按钮可以完美地工作,除非我无法使其保持不变他是图像的纵横比!!谢谢