为了账号安全,请及时绑定邮箱和手机立即绑定

根据文本量更改文本编辑的高度

根据文本量更改文本编辑的高度

潇潇雨雨 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 关注
  • 66 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信