【发布时间】:2011-03-16 17:01:15
【问题描述】:
我通过创建 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 中使用它时没有任何反应。
【问题讨论】: