繁体   English   中英

在 xml 布局中导入视图

[英]Importing a view in xml layout

我正在尝试在我正在制作的应用程序中使用AndroidQuickResponseCode 但是我很难找到一个在我自己的应用程序中运行的示例。

我已将问题缩小到布局文件中的一个引用,它说:

<com.jwetherell.quick_response_code.ViewfinderView
      android:id="@+id/viewfinder_view"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:background="@color/transparent">
  </com.jwetherell.quick_response_code.ViewfinderView>

当它尝试在布局中呈现 com.jwetherell.quick_response_code.ViewfinderView 时出错。 它应该能够在我作为库添加的 jar 文件中找到。 (它从那个 jar 中找到其他文件。)logcat 中的堆栈跟踪相当长,但这些行对我来说似乎是一个摘要:

11-23 11:22:57.055: E/AndroidRuntime(12552): FATAL EXCEPTION: main
11-23 11:22:57.055: E/AndroidRuntime(12552): Process: se.tii.vargis, PID: 12552
11-23 11:22:57.055: E/AndroidRuntime(12552): java.lang.RuntimeException: Unable to start activity ComponentInfo{se.tii.vargis/se.tii.vargis.CaptureActivity}: android.view.InflateException: Binary XML file line #26: Binary XML file line #26: Error inflating class com.jwetherell.quick_response_code.ViewfinderView
11-23 11:22:57.055: E/AndroidRuntime(12552): Caused by: android.view.InflateException: Binary XML file line #26: Binary XML file line #26: Error inflating class com.jwetherell.quick_response_code.ViewfinderView
11-23 11:22:57.055: E/AndroidRuntime(12552): Caused by: android.view.InflateException: Binary XML file line #26: Error inflating class com.jwetherell.quick_response_code.ViewfinderView
11-23 11:22:57.055: E/AndroidRuntime(12552): Caused by: java.lang.reflect.InvocationTargetException
11-23 11:22:57.055: E/AndroidRuntime(12552): Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f04000d

这似乎意味着它找不到xml布局文件中写入的com.jwetherell.quick_response_code.ViewfinderView。 有什么特殊的方法可以导入一些东西以便它可以在 xml 文件中使用吗?

我的活动代码是空的,它只用setContentView(R.layout.activity_capture);设置布局setContentView(R.layout.activity_capture);

看到你必须在你的项目中创建一个与https://github.com/phishman3579/android-quick-response-code/blob/master/src/com/jwetherell/quick_response_code/ViewfinderView.java相同的类

然后在 xml 文件中,您必须提供该文件的路径,因为您的包名称是“com.example.SampleHello”+您的类名“ViewfinderView”,因此您的 xml 将是这样的

<com.example.SampleHello.ViewfinderView
  android:id="@+id/viewfinder_view"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:background="@color/transparent">
</com.example.SampleHello.ViewfinderView>

将鼠标指针指向 ViewfinderView 并单击 ctrl + 单击然后 ViewfinderView 类打开意味着它正在获取类

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM