我相当与Java / Eclipse的经历,但我全新的Android开发,它被证明是一个很奇怪的野兽至今。目前,我想要建立了具有两个图像按钮的应用程序。我的XML如下:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="24dp"
android:text="@string/now_playing" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageButton
android:id="@+id/StartButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/start_button"
android:contentDescription="@string/start_button" />
<ImageButton
android:id="@+id/StopButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@drawable/stop_button"
android:contentDescription="@string/stop_button" />
</LinearLayout>
</LinearLayout>
这似乎是正确的,但是ImageButtons不图形布局选项卡上正确渲染,有是说,“下面的类不能被找到的消息: - 的ImageButton(更改为android.widget.ImageButton,修复构建路径,编辑XML)”。
环顾四周网上一点之后,我发现这个问题弹起几次在计算器上,但我无法找到任何令人满意的答案。最常见的答案是清理项目,但是这并没有为我做过什么。有什么建议么?
有时,在Eclipse图形布局选项卡是无法画出的东西,而代码是好的。尝试运行用的setContentView(R.layout.yourxml)一个简单的活动;看看发生什么事:
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.yourlayout);
}
}
发表您的logcat如果你仍然有错误。
编辑:哦,我没有看到:
关于你的第二的ImageButton,更换
android:text="@drawable/stop_button"
通过
android:src="@drawable/stop_button"
试图导入关于java中的ImageButton类。
import android.widget.ImageButton;