我通过创建SurfaceView类的子类创建了自己的视图。xml布局中的自定义视图
但是我无法弄清楚如何从xml布局文件中添加它。我目前的main.xml如下所示:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<View
class="com.chainparticles.ChainView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</LinearLayout>
我错过了什么?
编辑
更多信息
我的看法是这样的
package com.chainparticles;
public class ChainView extends SurfaceView implements SurfaceHolder.Callback {
public ChainView(Context context) {
super(context);
getHolder().addCallback(this);
}
// Other stuff
}
和正常工作是这样的:
ChainView cview = new ChainView(this);
setContentView(cview);
但尝试使用它当什么也没发生xml。
随着我的第一个layout我刚刚收到一个黑屏,与此应用程序崩溃,而不是。 – monoceres 2010-07-15 23:41:06
什么是堆栈跟踪? – Qberticus 2010-07-15 23:44:27
http://pastebin.com/u2t3jdMt – monoceres 2010-07-15 23:50:31