开发者

MutliLine EditText Resize To Fit Content Within ExpandableListView

开发者 https://www.devze.com 2023-04-03 17:04 出处:网络
I have a multiLine EditText field that I\'m defining within my layout for the row like this: <?xml version=\"1.0\" encoding=\"utf-8\"?>

I have a multiLine EditText field that I'm defining within my layout for the row like this:

 <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="320dp" android:layout_height="wrap_content"
android:background="@color/lightblue" android:focusable="false">
<RelativeLayout android:layout_width="fill_parent"
    android:layout_height="wrap_content" android:layout_marginLeft="14dp"
    android:layout_marginTop="4dp" android:layout_marginRight="14dp" android:focusable="false">
    <TextView android:textSize="12dp" android:layout_height="wrap_content"
        android:layout_width="wrap_content" androi开发者_StackOverflow社区d:id="@+id/tvLabel"
        android:width="80dp" android:textColor="@color/lbl_color_alt"
        android:text="LABEL:" android:layout_marginRight="18dp"></TextView>
    <EditText android:layout_width="fill_parent"
        android:layout_height="wrap_content" android:id="@+id/etValue"          
        android:layout_toRightOf="@+id/tvLabel" 
        android:singleLine="false" android:gravity="top|left"
        android:minLines="3"            
        android:inputType="textAutoCorrect|textCapSentences|textMultiLine"
        android:imeOptions="normal" android:textSize="12dp"             
        />
</RelativeLayout>

I can adjust the minLines attribute and the EditText will grow and shrink in size just fine. However, I want the field to adjust it's size based on it's pre-populated content. So that if the content contains 6 lines, it will adjust the height accordingly. Is there something I need to do in the code to allow for this? Ultimately, I want to handle readjusting the height in an onTextChanged listener as well (similar to iPhone).


I was programmatically hard setting the line height within the code with setLines() which was preventing the EditText from adjusting based on content. I had done this MUCH earlier in the project and had forgotten all about it.

0

精彩评论

暂无评论...
验证码 换一张
取 消