android edittext is not scrolling

2019-07-31 08:07发布

问题:

I have edittext. Now my edittext is wrapping content, i dont know why, i want it stay same size but be scrollable(vertical).

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<ImageView
    android:id="@+id/imageViewFull"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
 android:layout_weight="10"
    />

 <EditText
 android:id="@+id/editTextFull"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:clickable="false"
 android:ems="10"
 android:lines="1"
 android:maxLines="5"
 android:cursorVisible="false"
 android:scrollbars="vertical"
 android:focusable="false"
  android:focusableInTouchMode="false"
 android:inputType="textMultiLine"
  >

 <requestFocus />
 </EditText>


</LinearLayout>

And in java i set text with setText

回答1:

Try using EditText in ScrollView or take a look at this thread to make it scrollable programmatically.



回答2:

use:

<EditText
    android:id="@+id/editTextFull"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:clickable="false"
    android:ems="10"
    android:lines="1"
    android:maxLines="5"
    android:cursorVisible="false"
    android:scrollbars="vertical"
    android:focusable="false"
    android:focusableInTouchMode="false"
    android:inputType="textMultiLine"
     >

    <requestFocus />
</EditText>


回答3:

Have you tried to set your layout_height="wrap_content"?



回答4:

this works for me:

<ScrollView 
    android:layout_height="200dp"
    android:layout_width="match_parent">
    <EditText
        android:id="@+id/Emsg"
        android:hint="@string/texthint"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="5dp"
        android:textColor="#02960B"
        android:textSize="18sp" />
</ScrollView>

i have set the height by android:layout_height="200dp"