Android RelativeLayout code implementation is centered, the left and right sides of the target View

The code implements the RelativeLayou location attribute.

                val layout = RelativeLayout(context)
                val layoutParam =
                    RelativeLayout.LayoutParams(imgWidth, height)
                layout.layoutParams = layoutParam
                
           		val text = TextView(context)
             	val textParams = RelativeLayout.LayoutParams(imgWidth, 80)
                text.layoutParams = textParams
              	//设置textview在reltive布局中的rule,位置布局底部
                textParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM)
                //将text加到relative里面
                layout.addView(text, textParams)

Guess you like

Origin blog.csdn.net/qq_33431394/article/details/107488421