亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

根據文本量更改文本編輯的高度

根據文本量更改文本編輯的高度

瀟瀟雨雨 2022-09-01 19:50:15
因此,我試圖建立聊天和文本編輯你寫消息的地方。我想根據文本量更改高度。要知道的一件好事也是,這是在一個片段中。就像在信使或普通的消息傳遞應用程序中一樣。Kotlin:fun initTextWatcher(){        var tw: TextWatcher = object : TextWatcher {            override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {                val textview = viewOfLayout.chat_input_text                if (activity != null) {                    activity?.runOnUiThread {                        textview.height = 100                    }                }            }            override fun afterTextChanged(s: Editable) {}            override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {}        }        viewOfLayout.chat_input_text.addTextChangedListener(tw)    }XML: <android.support.constraint.ConstraintLayout            android:layout_width="0dp" android:layout_height="wrap_content"            android:background="@color/White"            app:layout_constraintEnd_toEndOf="parent"            app:layout_constraintStart_toStartOf="parent"            app:layout_constraintBottom_toBottomOf="parent"            android:id="@+id/chat_input_text_Send_container">        <Button                android:text="@string/Send"                android:layout_width="wrap_content"                android:layout_height="35dp"                android:id="@+id/chat_send_button" app:layout_constraintEnd_toEndOf="parent"                android:layout_marginEnd="10dp"                android:layout_marginBottom="10dp" app:layout_constraintBottom_toBottomOf="parent"                android:background="@drawable/chat_round_corners" android:textColor="@color/White"                android:textSize="15sp"/>
查看完整描述

1 回答

?
慕尼黑8549860

TA貢獻1818條經驗 獲得超11個贊

我通過在每次文本更改為的參數時設置布局參數來修復它。editText


fun initTextWatcher(){

        var tw: TextWatcher = object : TextWatcher {

            override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {

                val chat_textedit = viewOfLayout.chat_input_text

                if (activity != null) {

                    activity?.runOnUiThread {

                        val lparams = chat_textedit.layoutParams as ConstraintLayout.LayoutParams

                        chat_textedit.layoutParams = lparams

                    }

            }

        }

        override fun afterTextChanged(s: Editable) {}

        override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {}

    }

    viewOfLayout.chat_input_text.addTextChangedListener(tw)

}


查看完整回答
反對 回復 2022-09-01
  • 1 回答
  • 0 關注
  • 116 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號