如何在布局中使用自己的视图?

hit*_*tzi 7 xml layout android view

我创建了一个这样的类

public final class MyView extends View {

    public MyView(Context context, AttributeSet attrs) {
        super(context, attrs);
        [...]
    }
        [...]
}
Run Code Online (Sandbox Code Playgroud)

然后我想在layout.xml中使用它

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
             android:layout_width="fill_parent"
             android:layout_height="fill_parent">

  <com.hitziger.barcode.MyView
      android:id="@+id/my_view"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"/>

</FrameLayout>
Run Code Online (Sandbox Code Playgroud)

但Eclipse在错误日志中告诉我

AndroidManifest:忽略未知的'com.hitziger.barcode.MyView'XML元素

如何在布局中使MyView可访问?我必须在其他地方发表这个课吗?

MBy*_*ByD 11

你应该这样写:

<view class="com.hitziger.barcode.MyView"...
Run Code Online (Sandbox Code Playgroud)