添加自定义视图-Android

添加自定义视图-Android,android,android-layout,android-studio,android-custom-view,Android,Android Layout,Android Studio,Android Custom View,我有以下布局文件。它有半屏幕的相机预览和按钮。我想添加一个绘制圆的自定义视图。我已经完成了自定义视图类的编码。但是现在的问题是如何在布局中添加自定义视图,以及如何将其集成到我的主类中。到目前为止,我还没能使它正常工作 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_pa

我有以下布局文件。它有半屏幕的相机预览和按钮。我想添加一个绘制圆的自定义视图。我已经完成了自定义视图类的编码。但是现在的问题是如何在布局中添加自定义视图,以及如何将其集成到我的主类中。到目前为止,我还没能使它正常工作

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:baselineAligned="false">


<LinearLayout
    android:id="@+id/camera_preview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_weight="1"
    android:orientation="horizontal">
    <MyDrawing
        android:id="@+id/Drawing"
        android:layout_width="259dp"
        android:layout_height="fill_parent"
        android:orientation="horizontal"
        />

</LinearLayout>


<LinearLayout
    android:id="@+id/buttonsLayout"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="center"
    android:orientation="vertical"
    android:weightSum="1">

    <Button
        android:id="@+id/button_capture"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_marginTop="100dp"
        android:text="Capture/Stop"
        />
</LinearLayout>

更改此选项:

<MyDrawing
        android:id="@+id/Drawing"
        android:layout_width="259dp"
        android:layout_height="fill_parent"
        android:orientation="horizontal"
        />

致:



始终将完整路径添加到视图中

要添加的位置以及要添加的自定义视图要在相机预览上添加该自定义视图(绘制圆圈)。要在特定位置显示该路径吗??如何得到位置(像素)我只是画了一个圆(半径50f),它的半径是恒定的。只想把它显示在相机的中心或角落。稍后将在预览上动态移动它。但到目前为止,只是在预览中显示它是一个问题。Gowtham您能告诉我如何将它集成到我的主类onCreate方法中吗?上次我试图在我的主类中声明它时,它给出了布局充气器异常。“com.package.file.location.MyDrawing”行是否创建了此异常?您应该将“com.package.file.location”替换为您的包名这是一个很好的教程,您可以用来开始Gowtham,让我尝试一下,如果它能成功的话。我会尽快回复你的。现在谢谢你
<com.package.file.location.MyDrawing
        android:id="@+id/Drawing"
        android:layout_width="259dp"
        android:layout_height="fill_parent"
        android:orientation="horizontal"
        />