android自定义通知不适用于约束布局

android自定义通知不适用于约束布局,android,kotlin,notifications,android-constraintlayout,Android,Kotlin,Notifications,Android Constraintlayout,我花了一整天的时间来弄清楚为什么我的自定义通知没有显示出来。最后,是约束布局的问题。当我尝试使用约束布局构建custom_notification.xml时,通知不会显示,但如果我更改为线性布局,通知会工作。有谁能告诉我为什么会这样 具有线性布局的custom_notitication.xml(此布局有效) 还有我的房子 implementation 'com.android.support:appcompat-v7:28.0.0' implementation 'com.and

我花了一整天的时间来弄清楚为什么我的自定义通知没有显示出来。最后,是约束布局的问题。当我尝试使用约束布局构建custom_notification.xml时,通知不会显示,但如果我更改为线性布局,通知会工作。有谁能告诉我为什么会这样

具有线性布局的custom_notitication.xml(此布局有效)

还有我的房子

    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'com.android.support:support-v4:28.0.0'

通知布局使用与小部件相同的RemoteView实现

与RemoteView兼容的视图很少。它只是本机/框架视图(即无支持视图、无库视图、无自定义视图)的一个子集,并且该子集并非详尽无遗:

  • 适配器交换机
  • 框架布局
  • 网格布局
  • 网格视图
  • 线性布局
  • 列表视图
  • 相对论
  • 斯塔克维尤
  • 视窗翻转器
  • 模拟时钟
  • 钮扣
  • 天文钟
  • 图像按钮
  • 图像视图
  • 进度条
  • 文本时钟
  • 文本视图
其他视图都不起作用


通过通知检查支持的布局:
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="8dp">


    <Button
        android:id="@+id/button"
        android:layout_width="0dp"
        android:layout_weight="1"
        android:layout_height="wrap_content"
        android:layout_marginTop="8dp"
        android:text="Button"
        app:layout_constraintEnd_toStartOf="@+id/button2"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toStartOf="parent" />

    <Button
        android:layout_weight="1"
        android:id="@+id/button2"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="8dp"
        android:text="Button"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toEndOf="@+id/button"
        />
</android.support.constraint.ConstraintLayout>
  fun getNotification(context: Context): Notification {
        val mNotificationManager1: NotificationManager?

        val notification: Notification

        mNotificationManager1 = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
            createChannel(mNotificationManager1)

        val contentView = RemoteViews(applicationContext.packageName, R.layout.custom_notifaction)

        val mBuilder = NotificationCompat.Builder(applicationContext,"LockScreenTouch")
                .setSmallIcon(R.mipmap.ic_launcher)
                .setCustomBigContentView(contentView)
        notification = mBuilder.build()

        mNotificationManager1.notify(PostNotifactionActivity.ONGOING_NOTIFICATION_ID, notification)
        return notification
    }

    @TargetApi(26)
    @Synchronized
    private fun createChannel(notificationManager: NotificationManager?) {
        val name = "lockScreen"
        val importance = NotificationManager.IMPORTANCE_DEFAULT

        val mChannel = NotificationChannel("LockScreenTouch", name, importance)

        mChannel.enableLights(true)
        mChannel.lightColor = Color.BLUE
        notificationManager!!.createNotificationChannel(mChannel)
    }
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'com.android.support:support-v4:28.0.0'