我创建了一个继承自SurfaceView类的视图。
但是我不知道如何将它从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中尝试使用它时没有任何反应。