package com.bbx.bmtc.helper import android.content.Context import android.text.Layout import android.util.Pair import android.widget.TextView import com.bbx.bmtc.ext.isEmpty object ComputeHelper { private fun computeTextLen(context: Context, text:String):Float{ val tv = TextView(context) tv.text=text var tp = tv.paint return Layout.getDesiredWidth(tv.text.toString(),tp) } fun getTextMaxLen( context: Context,items: List<Pair<String, Int>>):Float{ if (isEmpty(items))return 0.0f var max:Float=0.0f items.map { var tempValue= computeTextLen(context,it.first) if(tempValue>max){ max=tempValue } } return max } }
Android 动态获取文本宽度
最新推荐文章于 2024-05-13 15:06:51 发布