我想在我的应用程序中的固定行数之后淡出长文本,就像他们在本 CSS 教程中所做的那样:
https://css-tricks.com/text-fade-read-more/
但我不知道要谷歌什么,也不知道如何实现这样的行为。有人可以帮我提供一些意见吗?
<FrameLayout
android:id="@+id/event_text_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:padding="28dp"
android:maxLines="15"
/>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/overlay_textview" />
</FrameLayout>
最佳答案
设置 TextView 的 maxLines 属性(或者只是将高度设置为某个具体值),在其上方放置一个带有渐变的 View 和一个按钮。处理代码中的按钮和渐变可见性。
button.setOnClickListener {
button.visibility = View.GONE
gradientView.visibility = View.GONE
textView.layoutParams.height = ViewGroup.LayoutParams.WRAP_CONTENT
textView.requestLayout()
}
关于java - TextView:淡出 + 阅读更多 - 单击展开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58476833/