首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >激活选项卡内的摄像机(android)

问激活选项卡内的摄像机(android)
EN

Stack Overflow用户
提问于 2011-03-14 07:04:48
回答 1查看 2.4K关注 0票数 3

我正在尝试开发一个具有3个选项卡的应用程序,以便第一个选项卡启用相机并捕获图像。到目前为止,我对相机有两个问题:

  1. ,我想要相机锁定在纵向或景观模式。如果我锁定相机的肖像,那么图像似乎旋转,我已经尝试了几乎所有与camera.parameters,但不能修复它。如果我锁定相机在景观模式,那么问题是标签菜单也改变方向为景观。是否有一种方法只改变该选项卡内的方向,并将选项卡菜单保留在纵向模式下?

,

  1. ,图像被某种方式拉伸。我想问题是相机使用的是全屏幕的高度和宽度,但我的应用程序试图将相机预览放在一个比屏幕小的框架内,这是因为选项卡菜单的缘故,这样图像就会被拉伸。有什么方法可以解决这个问题,并显示带有选项卡菜单的实际摄像机预览吗?

我使用创建3个选项卡的1个活动,并使用以下布局:

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@android:id/tabhost"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">
  <LinearLayout
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="5dp">
    <FrameLayout
        android:id="@android:id/tabcontent"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:padding="5dp"
        android:layout_weight="1"/>
    <TabWidget
        android:id="@android:id/tabs"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="0"/>
  </LinearLayout>
</TabHost>

我对每个选项卡使用一个活动。特别是对于第一个选项卡(照相机),我在以下布局中使用preview.class:

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout" android:orientation="vertical" android:layout_height="wrap_content" android:layout_width="wrap_content">
<FrameLayout android:layout_weight="1" android:id="@+id/preview" android:layout_gravity="fill_vertical" android:fitsSystemWindows="true" android:layout_height="wrap_content" android:layout_width="wrap_content">
</FrameLayout>
<Button android:text="Click" android:id="@+id/buttonClick" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_gravity="center"></Button>
</LinearLayout>
EN

回答 1

Stack Overflow用户

发布于 2011-04-12 10:15:36

我做了3个选项卡,其中第一个选项卡必须是相机预览在纵向模式,没有失真。好吧,这是可能的,有三个技巧:)

首先,使用纵向模式设置您的子预览活动,以强制选项卡处于纵向。在onCreate()中使用

代码语言:javascript
复制
this.getParent().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

或在舱单上

代码语言:javascript
复制
android:screenOrientation="portrait"

然后,要旋转屏幕,您不应该使用参数,因为它不工作,但(仅从2.2)

代码语言:javascript
复制
if (Build.VERSION.SDK_INT >= 8 ) camera.setDisplayOrientation(90);

最后,为了避免strectch,您可以使用全屏幕的FameLayout,并将其置于选项卡之下(选项卡就像一个覆盖层,但是下面的摄像头是全屏的,没有失真)。

代码语言:javascript
复制
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"/>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@android:id/tabs"/>

看哪!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5295705

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档