Android 使用xml的CustomView不';我不会出现在屏幕上

Android 使用xml的CustomView不';我不会出现在屏幕上,android,xml,android-layout,android-activity,android-linearlayout,Android,Xml,Android Layout,Android Activity,Android Linearlayout,我正在尝试将自定义视图添加到主活动的xml中。 我为视图创建了以下xml: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content"> <TextView android:layout_width="mat

我正在尝试将自定义视图添加到主活动的xml中。 我为视图创建了以下xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="Testing custom view"
        android:textSize="20dp" />
</LinearLayout>
在主要活动的xml中,我添加了如下自定义视图:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.myapplication.MainActivity">

<com.example.myapplication.TestView
    android:id="@+id/submit_area"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />
</LinearLayout>

当我运行应用程序时,我会看到一个空屏幕。它没有显示显示“测试自定义视图”的textview。 任何帮助都将不胜感激。
谢谢

您的自定义视图中的视图膨胀代码看起来是错误的。请按照下面给出的方法进行尝试

  LayoutInflater inflater = (LayoutInflater) context
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    inflater.inflate(R.layout.view_color_options, this, true);

自定义视图中的视图膨胀代码看起来有误。请按下面给出的方法进行尝试

  LayoutInflater inflater = (LayoutInflater) context
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    inflater.inflate(R.layout.view_color_options, this, true);

设置背景色TestView,然后检查它的显示或否,它不显示。更改了颜色,但未显示。设置背景色TestView,然后检查其显示或否否,其未显示。更改了颜色,但未显示。