我正在尝试开发一个具有3个选项卡的应用程序,以便第一个选项卡启用相机并捕获图像。到目前为止,我对相机有两个问题:
,
我使用创建3个选项卡的1个活动,并使用以下布局:
<?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:
<?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>发布于 2011-04-12 10:15:36
我做了3个选项卡,其中第一个选项卡必须是相机预览在纵向模式,没有失真。好吧,这是可能的,有三个技巧:)
首先,使用纵向模式设置您的子预览活动,以强制选项卡处于纵向。在onCreate()中使用
this.getParent().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);或在舱单上
android:screenOrientation="portrait"然后,要旋转屏幕,您不应该使用参数,因为它不工作,但(仅从2.2)
if (Build.VERSION.SDK_INT >= 8 ) camera.setDisplayOrientation(90);最后,为了避免strectch,您可以使用全屏幕的FameLayout,并将其置于选项卡之下(选项卡就像一个覆盖层,但是下面的摄像头是全屏的,没有失真)。
<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"/>看哪!
https://stackoverflow.com/questions/5295705
复制相似问题