<TextView
android:id="@+id/tvChangeBefore“
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="5"
/>
- 设置完TextView的文本之后,在异步线程中获取TextView的linCount,如果不在异步线程中进行获取的话,获取到的lineCount为0,因为TextView还没绘制完成。
holder.itemView.tvChangeBefore.post {
val beforeLine=holder.itemView.tvChangeBefore.lineCount
if (beforeLine<=5){
holder.itemView.llExpand.visibility=View.GONE
}else{
holder.itemView.llExpand.visibility=View.VISIBLE
holder.itemView.llExpand.setOnClickListener{
holder.itemView.ivIcon.rotation = rotation
holder.itemView.ivIcon.startAnimation(rotationAnim)
rotation = if (rotation == 0f) 180f else 0f
if (rotation==0f){
holder.itemView.tvExpand.text="展开"
holder.itemView.tvChangeBefore.maxLines=5
}else{
holder.itemView.tvExpand.text="收起"
holder.itemView.tvChangeBefore.maxLines= Int.MAX_VALUE }
}
}
}