Android基本布局-GridLayout_网格布局

使用:
xml

   <GridLayout
        android:id="@+id/gl_desc"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:columnCount="2"
        android:layout_gravity="center_horizontal"
        android:layout_marginTop="20dp">
    </GridLayout>

代码动态添加子孩子

        data.descItems?.forEachIndexed {
    
     index, s ->
            val tv = TextView(context)
            val layoutParams = GridLayout.LayoutParams()
            if (index == 0){
    
    
                layoutParams.bottomMargin = 14.dp
                layoutParams.rightMargin = 44.dp
            }
            tv.text = s
            tv.setLines(1)
            tv.setTextColor(context.getColor(R.color.color_222222))
            tv.textSize = 14f
            glDesc.addView(tv,layoutParams)
        }

猜你喜欢

转载自blog.csdn.net/weixin_38687303/article/details/128565497