Android相机在视图与按钮和文本 [英] Android Camera in View with Buttons and Text over

查看:156
本文介绍了Android相机在视图与按钮和文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的视图中实现了一个相机,就像在API演示中做的一样。但它只适用于横向模式。但是这对我来说不好,因为我想在肖像模式下使用它。所以按钮等看起来很不好。如何获得一个SurfaceView,它显示CameraPreview和所有一起工作在protrait模式?

I implemented a Camera in my View like it is done in the API Demos. But it only works in the landscape mode. But that's not good for me, because I want to use it mostly in the portrait mode. So the buttons and so on look very bad. How is it possible to get a SurfaceView, which shows the CameraPreview and all together works in the protrait mode?

我不认为有必要张贴代码因为我只是使用代码形式的API演示!

I don't think that it is necessary to post the code because I just used the code form the API demos!

非常感谢!

推荐答案

如果您没有在AndroidManifest.xml文件中指定屏幕方向,默认显示方向是横向位置,每次旋转手机时,Android将更改获取的图像,以保持图像与手机对齐。因此,您有两个选项:

If you do not specify the screen orientation in AndroidManifest.xml file, the default display orientation is the landscape position and every time you rotate the phone android will change the acquired image in order to maintain the image aligned with phone. Thus, you have two options:

1.1。在AndroidManifest.xml文件中指定屏幕方向,并正确设置屏幕方向:

1.1. Specify the screen orientation in AndroidManifest.xml file and set the properly screen orientation:

AndroidManifest.xml:

AndroidManifest.xml:

        <activity
        android:label="@string/app_name"
        android:name=".CameraPreview" 
        android:screenOrientation="portrait" >

CameraPreview.java:

CameraPreview.java:

       mCamera.setPreviewDisplay(holder);
       mCamera.setDisplayOrientation(90);

AndroidManifest.xml: / p>

AndroidManifest.xml:

        <activity
        android:label="@string/app_name"
        android:name=".CameraPreview" 
        android:screenOrientation="landscape" >

CameraPreview.java:

CameraPreview.java:

       mCamera.setPreviewDisplay(holder);
       mCamera.setDisplayOrientation(0);

1.2。不要在AndroidManifest.xml文件中指定屏幕方向,并在每次屏幕旋转时设置正确的屏幕方向:

1.2. Do not specify the screen orientation in AndroidManifest.xml file and set the properly screen orientation every time the screen is rotated:

    public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {

      int rotation = ((Activity)mCtx).getWindowManager().getDefaultDisplay().getRotation();
      int degrees = 0;
      switch (rotation) {
        case Surface.ROTATION_0: degrees = 90; break;
        case Surface.ROTATION_90: degrees = 0; break;
        case Surface.ROTATION_180: degrees = 270; break;
        case Surface.ROTATION_270: degrees = 180; break;
      }

      mCamera.setDisplayOrientation(degrees);

      Camera.Parameters parameters = mCamera.getParameters();
      parameters.setPreviewSize(w, h);
      mCamera.setParameters(parameters);
      mCamera.startPreview();
    }

但是,因为你似乎已经设计了一个纵向布局,所以,我认为最好的选择是第一个。

But since, it seems that you already have designed a portrait layout with buttons and so on, I think the best option is the first one.

希望这有助于和最好的问候。

Hope this helps and best regards.

这篇关于Android相机在视图与按钮和文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆