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

前端之家收集整理的这篇文章主要介绍了android – 如何在布局中使用自己的视图?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我创建了一个这样的类
  1. public final class MyView extends View {
  2.  
  3. public MyView(Context context,AttributeSet attrs) {
  4. super(context,attrs);
  5. [...]
  6. }
  7. [...]
  8. }

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

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="fill_parent"
  4. android:layout_height="fill_parent">
  5.  
  6. <com.hitziger.barcode.MyView
  7. android:id="@+id/my_view"
  8. android:layout_width="fill_parent"
  9. android:layout_height="fill_parent"/>
  10.  
  11. </FrameLayout>

但Eclipse在错误日志中告诉我

AndroidManifest: Ignoring unknown
‘com.hitziger.barcode.MyView’ XML
element

如何在布局中使MyView可访问?我是否必须在其他地方发表这门课程?

解决方法

你应该写它:
  1. <view class="com.hitziger.barcode.MyView"...

猜你在找的Android相关文章