我创建了一个带有LinearLayout的xml文件。然后,我想从后端加载一些项目并显示与从后端收到的项目一样多的卡片视图,因此我需要以编程方式将卡片视图添加为线性布局的子元素,对吗?
所以我做了以下事情:
MyHomeActivity
override fun onCreate(savedInstanceState: Bundle?) {
...
// Loading previously played games
val matches = matchService.getMatches(5, 0)
val matchListLayout = findViewById<LinearLayout>(R.id.match_list_layout)
matchCardViewCreator = MatchCardViewCreator(applicationContext)
// create view based on matches, for testing purposes I only display the first one
val matchCardZero = matchCardViewCreator.createCard(matches.content[0])
matchListLayout.addView(matchCardZero)
}
但是,我在活动的空白屏幕上看不到任何内容。我在做什么错了?