Chat page input box and send button layout issues Android

Source: Internet
Author: User

The layout file is as follows

<?xml version= "1.0" encoding= "Utf-8"? ><relativelayout xmlns:android= "http://schemas.android.com/apk/res/    Android "android:orientation=" vertical "android:layout_width=" fill_parent "android:layout_height=" Fill_parent " ><tablelayout android:id= "@+id/bottom_content" android:layout_width= "Fill_parent" android:layout_height= "        50DP "android:layout_alignparentbottom=" true "> <TableRow> <tablerow android:layout_weight=" 3 ">      <edittext android:hint = "@string/input_info" android:id = "@+id/messagetext"/> </TableRow> <tablerow android:layout_weight= "1" > <button android:text= "@string/send_msg" Android:id = " @+id/messagebutton "/> </TableRow> </TableRow></TableLayout> <listview android:id=" @+id/lis T "android:layout_width=" fill_parent "android:layout_height=" wrap_content "android:layout_alignparenttop =" Tru E "android:layout_above=" @+id/bOttom_content "/></relativelayout> 


Make the input box 3/4 of the width of the screen, and the width of the Send button is 1/4 of the screen width.

However, when you enter too much text and close the input keyboard or open the input keyboard, the width of the input box will squeeze the Send button, and when the text width reaches a certain width, the send button will "disappear" (invisible State).

Here is a simple workaround: Set a listener Addtextchangedlistener for the edittext in Java code, listen for changes to the input, and then rewrite the OnTextChanged method so that the width of the input box is 3 of the full screen 4, the width of the Send button takes up 1/4 of the full screen.

The core code is as follows: You only need to set the input box and the Send button width in ontextchanged to 3/4 and 1/4 respectively.

Messagesend= (Button) Findviewbyid (R.id.messagebutton);
edittext= (EditText) Findviewbyid (R.id.messagetext); Edittext.addtextchangedlistener (new Textwatcher () {@ overridepublic void OnTextChanged (charsequence arg0, int arg1, int arg2, int arg3) {edittext.setwidth ((3*screenwidth)/4) ; Messagesend.setwidth (SCREENWIDTH/4);} @Overridepublic void beforetextchanged (charsequence arg0, int arg1, int arg2,int arg3) {} @Overridepublic void Aftertextch Anged (Editable arg0) {}}); <span style= "font-family:arial; Background-color: #ffffff "></span>

Chat page input box and send button layout issues Android

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.