LoginSignup
0
0

More than 1 year has passed since last update.

特定のViewがセットされてからUIをさらに更新する方法

Posted at

たまに使うので忘れないようにメモ

どういうこと?(使用例)

  • 3行以上で省略されるTextViewの下部に、全文表示ボタンをつけたい
  • 省略されない場合はボタンを非表示にしたい
  • そのため、TextViewが表示されたタイミングで省略可能判定を行いたい。

結論

コード例

(DataBindingを使います)

// View#post()を使います
binding.textView.post {
  binding.textView.layout?.let { layout ->
    val ellipsisCount = layout.getEllipsisCount(MAX_LINES - 1)
    if (ellipsisCount == 0) {
      binding.moreButton.visibility = View.GONE
    } else {
      binding.moreButton.visibility = View.VISIBLE
  }
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0