前言
以博文展示的页面为例子:
每个博客都有自己对应的标签,而且标签的数量可能并不是一个。
按照原来的那种绘制界面的方式来说,只能是静态数量的组件个数然后设置对应的显示效果。
在Vue.js开发中,Vue自身提供了v-for来遍历添加,而且html和css搭配起来也很方便。
但是在Android开发中,因为在xml中没有办法做到for循环遍历添加。
只能通过尝试在Kotlin代码中来完成相应的操作。
xml中绘制存放动态组件的Layout
在博文展示的页面放置一个tag的list
<LinearLayout
android:id="@+id/blog_tag_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_marginTop="16dp"
android:orientation="horizontal" />
kotlin中获取view
val tagLayout: LinearLayout = findViewById(R.id.blog_tag_list)
然后首先移除