【发布时间】:2019-07-06 17:49:25
【问题描述】:
我有一个TextView,它有多行文本,我想在最后一行文本的末尾显示一个图标。我尝试了几种方法来获取我的 textview 的 x 和 y 值:
myTextView.viewTreeObserver.addOnGlobalLayoutListener {
val layout = myTextView.layout
val lines = myTextView.lineCount
val myImage = ImageView(activity)
myImage.imageResource = R.drawable.ic_icon
// a few ways I tried
val possibleY = layout.getLineTop(lines).toFloat()
streamTitleView.measure(0, 0)
val possibleY2= myTextView.top.toFloat()
// same for x value
myImage.x= //x end of last line of text
myImage.y= //y end of last line of text
content.addView(myImage)
}
这并没有给我正确的值。那么有什么方法可以为TextView 中最后一行的文本获取 x 和 y,以便我可以使用这些值为我的 imageview 设置 x 和 y?
【问题讨论】: