EditText grows with text input

I have an edittext, which is 80% of the screen, and a button that should take the remaining 20%, but when the text is entered into the field or deleted, the edittext grows and contracts.

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical"> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:weightSum="100"> <Button android:id="@+id/people_relationFilterB" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="20" /> <EditText android:id="@+id/people_searchBoxET" android:text="Search Known" android:singleLine="true" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="80" /> </LinearLayout> <ListView android:id="@+id/people_listLV" android:layout_width="fill_parent" android:layout_height="wrap_content" /> </LinearLayout> 

Any clues? Thanks!

+4
source share
3 answers

I believe your problem is that you set the width of the EditText layout as wrap_content. I had this problem when I started developing Android. You essentially tell Android that you want your EditText itself to match the text you entered.

The solution is to set the width of the layout as fill_parent, and then, if necessary, wrap the LinearLayout around it so that it contains the size.

+4
source

Try setting android: layout_width = "0dp"

+15
source

Try installing EditText

 android:layout_width="0dp" android:layout_weight="1" 
0
source

Source: https://habr.com/ru/post/1347733/


All Articles