Android积木之LayoutParams使用


    private fun createLabel(name: String?): TextView {
        val tv = TextView(mContext)
        tv.text = name
        val params = LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)
        params.setMargins(ResUtils.getDimension(R.dimen.x20).toInt(), 0, 0, ResUtils.getDimension(R.dimen.y20).toInt())
        tv.layoutParams = params
        tv.setBackgroundResource(R.drawable.topic_bg)
        tv.setPadding(ResUtils.getDimension(R.dimen.x16).toInt(), ResUtils.getDimension(R.dimen.y8).toInt(), ResUtils.getDimension(R.dimen.x16).toInt(), ResUtils.getDimension(R.dimen.y8).toInt())
        tv.setTextColor(ResUtils.getColor(R.color.color_999999))
        flexLayout?.addView(tv)
        return tv
    }

 

你可能感兴趣的:(Android积木)