问题描述
我试图建立一个Android应用程序,将拍摄一张照片,并以某种方式处理它。我想布局类似于谷歌护目镜。意,相机preVIEW在上面,并利用纵向在底部一些控制
I trying to put together an Android app that will take a picture and process it in some way. I'd like the layout to be similar to Google Goggles. Meaning, camera preview on the top, and some controls on the bottom using portrait orientation.
我已经建立了使用code样品从这里第一个版本。这工作,但我想补充一个在底部的按钮。
I've built a first version using code sample from here. This works, but I want to add a button on the bottom.
我已经修改了我的main.xml以如下所示(基于这篇文章的评论):
I've modified my main.xml to look as follows (based on comments from this post):
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<android.view.SurfaceView android:id="@+id/preview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentTop="true" />
<Button android:id="@+id/snap"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Snap"
android:layout_alignParentBottom="true" />
</RelativeLayout>
但是,当我运行此code,我得到了以下异常:
But when I run this code I get the following exception:
E/AndroidRuntime( 199): Uncaught handler: thread main exiting due to uncaught exception
E/AndroidRuntime( 199): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.beerometer/com.beerometer.ImageCapture}: android.view.InflateException: Binary XML file line #6: Error inflating class Android.view.SurfaceView
E/AndroidRuntime( 199): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)
E/AndroidRuntime( 199): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
E/AndroidRuntime( 199): at android.app.ActivityThread.access$2200(ActivityThread.java:119)
E/AndroidRuntime( 199): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
E/AndroidRuntime( 199): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 199): at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime( 199): at android.app.ActivityThread.main(ActivityThread.java:4363)
E/AndroidRuntime( 199): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 199): at java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime( 199): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
E/AndroidRuntime( 199): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
E/AndroidRuntime( 199): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime( 199): Caused by: android.view.InflateException: Binary XML file line #6: Error inflating class Android.view.SurfaceView
E/AndroidRuntime( 199): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:576)
E/AndroidRuntime( 199): at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
E/AndroidRuntime( 199): at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
E/AndroidRuntime( 199): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
E/AndroidRuntime( 199): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
E/AndroidRuntime( 199): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:198)
E/AndroidRuntime( 199): at android.app.Activity.setContentView(Activity.java:1622)
E/AndroidRuntime( 199): at com.beerometer.ImageCapture.onCreate(ImageCapture.java:37)
E/AndroidRuntime( 199): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
E/AndroidRuntime( 199): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
E/AndroidRuntime( 199): ... 11 more
E/AndroidRuntime( 199): Caused by: java.lang.ClassNotFoundException: Android.view.SurfaceView in loader dalvik.system.PathClassLoader@44bfc7b0
E/AndroidRuntime( 199): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
E/AndroidRuntime( 199): at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
E/AndroidRuntime( 199): at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
E/AndroidRuntime( 199): at android.view.LayoutInflater.createView(LayoutInflater.java:466)
E/AndroidRuntime( 199): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:565)
E/AndroidRuntime( 199): ... 20 more
当我用别的东西,如更换上面的SurfaceView一个TextView,它显示,但在景观。
When I replace the SurfaceView above with something else, e.g. a TextView, that it displays, but in landscape.
如何使用纵向视图可我得到一个摄像头preVIEW屏幕的一部分?
How can I get a camera preview on part of the screen using portrait view?
感谢
推荐答案
首先,你的布局可能不会给你想要的东西。考虑使用 RelativeLayout的
,与按钮
锚定在底部,而 SurfaceView
锚定在屏幕的顶部和按钮的顶
First, your layout probably won't give you what you want. Consider using a RelativeLayout
, with the Button
anchored to the bottom, and the SurfaceView
anchored to the top of the screen and the top of the Button
.
此外,你有一个重复的的xmlns:机器人=http://schemas.android.com/apk/res/android
在 SurfaceView
,你不需要。一个根元素就足够了。
Also, you have a duplicate xmlns:android="http://schemas.android.com/apk/res/android"
on your SurfaceView
that you don't need. The one on your root element will suffice.
在你的异常方面,有可能会在您的堆栈跟踪的更多细节,你错过了,解释了为什么启动preVIEW()
失败。寻找一个通过堆栈跟踪引发的或其他线路的中途。如果不能识别它,编辑您的问题,并在整个堆栈跟踪粘贴(并通过评论ping通我的这个答案,因为我不知道编辑以其他方式)。
In terms of your exception, there may be more detail in your stack trace that you are missing, explaining why startPreview()
failed. Look for a "Caused by" or other line mid-way through the stack trace. If you can't identify it, edit your question and paste in the entire stack trace (and ping me via a comment on this answer, since I won't know about the edit otherwise).
您还可能尝试本书实例中的另一个摄像机
preVIEW应用程序,看看是否有一些关于我如何对待一个适合你的情况更好的问题。
You might also experiment with this book example as another Camera
preview app, to see if there's something about how I approach the problem that works better for your circumstance.
这篇关于在屏幕的一部分使用android.view.SurfaceView用照相机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!