How to make an EditText scrollable inside a scroll

2019-06-13 03:51发布

问题:

The LinearLayout scrolls but the EditText doesn't.

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="top"
        android:orientation="vertical" >


        <EditText
            android:id="@+id/messageeditor_editText2"
            android:layout_width="match_parent"
            android:layout_height="200dp"/>

    </LinearLayout>
</ScrollView>

I am setting EditText scrollable with:

editText.setMovementMethod(new ScrollingMovementMethod());

EDIT:

I tried to do the following but don't know how to disable my scrollview, this is a focus change listener for my edittext:

private OnFocusChangeListener focuschangelistener = new OnFocusChangeListener(){

    @Override
    public void onFocusChange(View arg0, boolean arg1) {
        if(arg1){
            sv.setEnabled(false);
        }else{
        }           
    }

};

回答1:

did you find solution? someone said that below code can solve problem

final EditText myEditText = (EditText) findViewById(R.id.EditText01);
myEditText.setMovementMethod(new ScrollingMovementMethod());


回答2:

you have given fix height that is 200dp please change it to match_parent or increase it. Then check.

It will work as you want.

Feel free to comments.