Refresh
我面临的问题是,我无法向XML文件中添加新的图像按钮。我向Drawable中添加了图标,但无法在图像按钮中显示。 XML显示未找到错误ImageButton类。我该如何解决?
我在xml中遇到以下错误
找不到以下类:-ImageButton(更改为android.widget.ImageButton,修复构建路径,编辑XML)
这是我的xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageButton
android:id="@+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="109dp"
android:src="@drawable/facebook" />
</RelativeLayout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageButton
android:id="@+id/image1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="109dp"
android:src="@drawable/yourimage1" />
<ImageButton
android:id="@+id/image2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="164dp"
android:src="@drawable/your image2" />
</RelativeLayout>
我认为很奇怪,或确保图像在可绘制文件夹中的格式正确
为什么不尝试使用简单的按钮而不是图像按钮。这是我在某些带有图像按钮上的代码。android:drawableTop="@drawable/three"
:这基本上是图像android:background="@drawable/buttonstyles"
:这是按钮的样式。无需使用。或我拥有的其他布局功能。
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/button2"
android:layout_alignParentRight="true"
android:layout_marginRight="20dp"
android:background="@drawable/buttonstyles"
android:drawableTop="@drawable/three"
android:onClick="goToSettings"
android:text="Settings" />
我有同样的问题。我的图像是.ico,并且在eclipse的“图形布局”选项卡中有相同的错误消息。我证明了将.ico图像转换为.png图像,然后删除了.ico,然后将.png导入到项目中。成功了。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageButton
android:id="@+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="109dp"
android:src="@drawable/a" />
<ImageButton
android:id="@+id/imageButton3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="164dp"
android:src="@drawable/a" />
</RelativeLayout>
我认为这不是大问题。您是对的,您发布的内容没有错。在我的日食中工作正常。
如果重新启动eclipse,则它不起作用,可能是您的项目库位置不正确。
Refresh
更改为此项以使其起作用并在图像按钮中显示图像
clean