简体   繁体   English

在 xml 布局中导入视图

[英]Importing a view in xml layout

I'm trying to use AndroidQuickResponseCode in an app I am making.我正在尝试在我正在制作的应用程序中使用AndroidQuickResponseCode But I have a hard time getting an example to run inside my own app.但是我很难找到一个在我自己的应用程序中运行的示例。

I have narrowed down the problem to a reference in a layout file, where it says:我已将问题缩小到布局文件中的一个引用,它说:

<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>

It goes wrong when it tries to render the com.jwetherell.quick_response_code.ViewfinderView in the layout.当它尝试在布局中呈现 com.jwetherell.quick_response_code.ViewfinderView 时出错。 This it should be able to find in the jar file that I've added as a library.它应该能够在我作为库添加的 jar 文件中找到。 (It finds other files from that jar.) The stacktrace in logcat is rather long, but these lines seem like a summary to me: (它从那个 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

It seems to means that it can't find the com.jwetherell.quick_response_code.ViewfinderView that is written in the xml layout file.这似乎意味着它找不到xml布局文件中写入的com.jwetherell.quick_response_code.ViewfinderView。 Is there any special way on importing something so that it can be used in an xml file?有什么特殊的方法可以导入一些东西以便它可以在 xml 文件中使用吗?

My Activity code is empty, it only sets the layout with setContentView(R.layout.activity_capture);我的活动代码是空的,它只用setContentView(R.layout.activity_capture);设置布局setContentView(R.layout.activity_capture);

See you have to make a class in your project same as https://github.com/phishman3579/android-quick-response-code/blob/master/src/com/jwetherell/quick_response_code/ViewfinderView.java看到你必须在你的项目中创建一个与https://github.com/phishman3579/android-quick-response-code/blob/master/src/com/jwetherell/quick_response_code/ViewfinderView.java相同的类

and then in xml file you have to give the path of that file as your package name is "com.example.SampleHello" + your class name "ViewfinderView" so your xml will be like this然后在 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>

Take mouse pointer to the ViewfinderView and click ctrl + click then ViewfinderView class open means it is getting class将鼠标指针指向 ViewfinderView 并单击 ctrl + 单击然后 ViewfinderView 类打开意味着它正在获取类

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

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