开发者

How to use own view in layout?

I created a class like this

public final class MyView extends View {

    public MyView(Context context, AttributeSet attrs) {
        super(context, attrs);
        [...]
    }
        [...]
}

and then I want to use it within my 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>

But Eclipse tells me in the error log

AndroidManifest: Ignoring unknown 'com.hitziger.barcode.MyView' XML element

How can I make MyView accessable within a layout? Do I have to publish this class elsewhere?


You should write it like:

<view class="com.hitziger.barcode.MyView"...


in the layout.xml, use:

<View 
    android:class="com.hitziger.barcode.MyView"
    android:id="@+id/my_view"
...

istead of:

<com.hitziger.barcode.MyView
    android:id="@+id/my_view"
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜