EditText not scrollable inside ScrollView

2019-01-13 10:04发布

I have a ScrollView inside which is an EditText which is set to scroll vertically. But it does not scrolls. Instead the whole layout scrolls, Whenever i try to scroll the EditText. Below is the code -

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

<TextView
    android:id="@+id/b1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="39dp"
    android:text="Title"
    android:textColor="#3bb9ff"
    android:textSize="15sp" />

<EditText
    android:id="@+id/Text1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:ems="10"
    android:hint="Title"
    android:singleLine="true" >

    <requestFocus />

</EditText>

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Content"
    android:layout_marginTop="50dp"
    android:textColor="#3bb9ff"
    android:textSize="15sp"
   />


<EditText
    android:id="@+id/newTodoText"
    android:layout_width="fill_parent"
    android:layout_height="match_parent" 
    android:minLines="2"
    android:maxLines="7"
     android:hint="Write something"
     android:scrollbars = "vertical" >
</EditText>
<Button
    android:id="@+id/Add"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:text="Add" />


</LinearLayout>
</ScrollView>

The EditText with id "newTodoText" is in question here.

10条回答
我想做一个坏孩纸
2楼-- · 2019-01-13 10:31

A simple way to do so is mentioned below with some description

            myEditText.setOnTouchListener(new View.OnTouchListener() {  //Register a callback to be invoked when a touch event is sent to this view.
            @Override
            public boolean onTouch(View v, MotionEvent event) {     
//Called when a touch event is dispatched to a view. This allows listeners to get a chance to respond before the target view.
                mScrollView.requestDisallowInterceptTouchEvent(true);
                return false;
            }
        });
查看更多
我只想做你的唯一
3楼-- · 2019-01-13 10:43
noteEdit.setMovementMethod(new ScrollingMovementMethod());
    ScrollingMovementMethod.getInstance();


    noteEdit.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {

            noteEdit.getParent().requestDisallowInterceptTouchEvent(true);

            return false;
        }


    });
查看更多
够拽才男人
4楼-- · 2019-01-13 10:46

You have set "Scroll View" to your parent - this means it scrolls the whole layout.

If you want to scroll a particular "Edit text" then you have to put another Scroll view to that edit text.

查看更多
forever°为你锁心
5楼-- · 2019-01-13 10:48
mEdtText1.setOnTouchListener(new View.OnTouchListener() { 
            @Override
            public boolean onTouch(View view, MotionEvent motionEvent) {
                mScrlMain.requestDisallowInterceptTouchEvent(true);
                return false;
            }
        });

// change hear mEdtText1 with your edit text object and also change mScrlMain with your scroll view object they work definitely.

查看更多
登录 后发表回答