最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

android - why a created view can't be saw in layoutInspector without filter system-defined layers option checked, but in

programmeradmin3浏览0评论

i'm writing a demo and find a wired thing:

a created view(new View(context) and then parent.addView(childView)) can't be saw in Layout Inspector without filter system-defined layers option checked; but the inflated view(layoutInflater.inflate(R.layout.xxx, null)) can.

i tried to ask Google Gemini and the gemini told me:

When you create a view programmatically (e.g., new TextView(context)) and add it to your Activity's view hierarchy, it might be added to a system-managed layer, especially if you're adding it to a container that is itself part of the system's UI (e.g., a Dialog, PopupWindow, or a custom view that interacts with system UI elements). This isn't always the case, but it's a possibility.

but this answer looks right but useless(did't specify the deeper reason), so i'm here for help, and here's the code i wrote

// can't be shown in hierarchy
val tempTextViewCompat = AppCompatTextView(this).apply {
     layoutParams = LinearLayoutCompat.LayoutParams(
         ViewGroup.LayoutParams.MATCH_PARENT,
         ViewGroup.LayoutParams.WRAP_CONTENT
     )
     text = "Hello World"
     textSize = 30f
}
mainView.addView(tempTextViewCompat)

// can be shown in hierarchy
val inflateView = layoutInflater.inflate(R.layout.temp_text, null)
mainView.addView(inflateView)

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论