Android在摄像头上方显示可调整大小的矩形

Android在摄像头上方显示可调整大小的矩形,android,android-camera,Android,Android Camera,我正试图构建一个Android程序,在相机视图上有一个可调整大小的矩形,并以此为指导: 我已经被困了一天,因为我无法查看相对布局上的显示,也找不到问题(我是相对新的) 这是我的XML文件: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" and

我正试图构建一个Android程序,在相机视图上有一个可调整大小的矩形,并以此为指导:

我已经被困了一天,因为我无法查看相对布局上的显示,也找不到问题(我是相对新的)

这是我的XML文件:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<RelativeLayout
    android:id="@+id/camera_preview"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <View
        android:id="@+id/camera_box"
        android:layout_alignParentTop="true"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@android:color/transparent">
    </View>

    <Button
        android:id="@+id/button_ChangeCamera"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@android:color/white"
        android:text="Switch Camera"
        android:textColor="@android:color/holo_orange_dark"
        android:layout_marginTop="30dp"
        android:layout_marginRight="30dp"
        android:minWidth="100dp"
        android:layout_alignParentTop="true"
        android:layout_alignParentRight="true"/>
    <Button
        android:id="@+id/button_capture"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="30dp"
        android:background="@android:color/white"
        android:text="Capture"
        android:textColor="@android:color/holo_orange_dark"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"/>

</RelativeLayout>
DrawView覆盖onDraw并实现onTouchEvent,基本上与Nguyen Minh Binh在中发布的解决方案相同:

有人能帮我弥补我所缺少的吗

谢谢

您创建了DrawView类的新对象,但在下一行中,您为同一变量指定了不同的对象。DrawView现在基本上丢失了。您可以使用
addView(drawView)
代替第二行,但最简单的方法是使用

<…package…DrawView android:id="@+id/camera_box"

谢谢!那就更有意义了!已经修好了,t现在工作正常了。:)
drawView = new DrawView(myContext);
drawView = findViewById(R.id.camera_box);
<…package…DrawView android:id="@+id/camera_box"