问题描述
当我使用自定义字体时,布局编辑器不显示自定义视图。但是,它在我运行应用程序时有效。
当我编写分配字体的行时,它不显示视图。
textValuePaint = TextPaint().apply {
textSize = DimensionsUtils.dpToPx(context,24f)
typeface = ResourcesCompat.getFont(context,R.font.alex_brush)
}
它还说不支持 Path.op()。我不知道这是否与我的问题有关。
有人可以帮我吗?
解决方法
编辑模式不支持某些操作,因此您无法在预览中看到它们。为了克服这个问题,您应该只在运行时运行此类操作。为此,您可以在自定义视图中使用 isInEditMode() 方法。例如
public override string Name
{
get
{
return $"{base.Name} ({this.year})";
}
}