Android Studio 3.2无法在Library Module中预览自定义控件

问题描述

在Android Studio 3.2中的Library Module中无法预览自定义控件。而在3.1.2中就没有问题。

相关代码

// 请把代码文本粘贴到下方(请勿用图片代替代码)
简单自定义控件代码:

class IconLabel : LinearLayout {
  constructor(context: Context?) : super(context)
  constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs)
  constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs,
      defStyleAttr)

  @RequiresApi(Build.VERSION_CODES.LOLLIPOP)
  constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int, defStyleRes: Int) : super(
      context, attrs, defStyleAttr, defStyleRes)

  init {

    val view = ImageView(context)
    view.setImageResource(R.mipmap.ic_launcher)
    addView(view, LayoutParams(100, 100))

  }
}

在application项目中的预览效果:
图片描述

在library中的预览效果:
图片描述

阅读 2.3k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进