class FirstActivity : AppCompatActivity(), View.OnClickListener {
private lateinit var binding: FirstLayoutBinding
private var isExpandTV_1 = false
private var isExpandTV_2 = true
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = FirstLayoutBinding.inflate(layoutInflater)
setContentView(binding.root)
// tv_expand.maxLines = 10
button.setOnClickListener(this)
button2.setOnClickListener(this)
}
fun showTv1Expand() {
tv_expand.maxLines = 10
//imageView 1
}
fun showTv1Collapse() {
tv_expand.maxLines = 0
// imageView 2
}
fun showTv2Expand() {
tv_expand2.maxLines = 10
}
fun showTv2Collapse() {
tv_expand2.maxLines = 0
// imageView 2
}
override fun onClick(v: View?) {
when (v) {
button -> {
if (isExpandTV_2) {
showTv2Collapse()
isExpandTV_2 = false
}
if (isExpandTV_1) {
showTv1Collapse()
isExpandTV_1 = false
} else {
showTv1Expand()
isExpandTV_1 = true
}
}
button2 -> {
if (isExpandTV_1) {
showTv1Collapse()
isExpandTV_1 = false
}
if (isExpandTV_2) {
showTv2Collapse()
isExpandTV_2 = false
} else {
showTv2Expand()
isExpandTV_2 = true
}
}
}
}
}
两个联动的可扩展收起的textView的简单实现
最新推荐文章于 2024-07-14 11:38:47 发布