【问题标题】:Create tap to capture transparent ImageButton over CameraPreview创建点击以在 CameraPreview 上捕获透明 ImageButton
【发布时间】:2014-02-25 21:11:00
【问题描述】:

一段时间以来,我一直在用这个把我的头撞到墙上。基本上我的应用程序显示了一个充满屏幕的相机预览,当用户点击预览时,它会捕获一个图像(试图通过一个透明的图像按钮来做到这一点。在屏幕底部我想要另一个图像按钮,这次它会停止应用程序正在进行的录制。

这是我的活动布局

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <FrameLayout
            android:id="@+id/camera_preview"
            android:layout_width="match_parent"
            android:layout_height="match_parent" >
        </FrameLayout>

        <ImageButton
            android:id="@+id/button_capture"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@null"
            android:contentDescription="@string/capture"
            android:src="@null" />
    </FrameLayout>

    <ImageButton
        android:id="@+id/stopRecording"
        android:layout_width="150dp"
        android:layout_height="150dp"
        android:layout_gravity="bottom|center"
        android:layout_marginBottom="50dp"
        android:background="@null"
        android:contentDescription="@string/stopRec"
        android:onClick="moveToUpload"
        android:scaleType="fitCenter"
        android:src="@drawable/rec_gray" />

</FrameLayout>

我尝试使用 FrameLayouts,因为它们允许覆盖。

唯一不变的是 CameraPreview 必须是 FrameLayout。

如有任何帮助,请更正此代码,

谢谢。

【问题讨论】:

    标签: android android-camera imagebutton


    【解决方案1】:

    如果您想在预览中添加按钮,请使用单独的布局并将它们合并到主布局中

    <merge xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >
    
    
        <include
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            layout="@layout/layout2" />
    
        <include
             android:layout_width="fill_parent"
             android:layout_height="fill_parent"
             layout="@layout/layout1" />
    </merge>
    

    一个布局将仅包含预览,第二个将包含按钮,合并后您将在预览上放置按钮。

    如果您想使用透明按钮,请使用带有 alpha chanel 的 png 文件,这样就可以了:)

    【讨论】:

      【解决方案2】:

      你需要像这样在你的xml中添加Cameraview

      <FrameLayout 
        android:id="@+id/mySurfaceView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
      
        <com.cam.CapturePreview 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">
        </com.cam.CapturePreview>
      
        </FrameLayout>
      

      这也会帮助你..https://stackoverflow.com/a/7528543/472336

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2013-05-07
        • 1970-01-01
        • 2012-10-01
        • 2021-04-18
        • 1970-01-01
        • 1970-01-01
        • 2012-05-04
        相关资源
        最近更新 更多