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

前端之家收集整理的这篇文章主要介绍了android – 如何在布局中使用自己的视图?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我创建了一个这样的类
public final class MyView extends View {

    public MyView(Context context,AttributeSet attrs) {
        super(context,attrs);
        [...]
    }
        [...]
}
@H_404_4@然后我想在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>
@H_404_4@但Eclipse在错误日志中告诉我

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

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

解决方法

你应该写它:
<view class="com.hitziger.barcode.MyView"...
原文链接:https://www.f2er.com/android/315913.html

猜你在找的Android相关文章