EditText not scrollable inside ScrollView

前端 未结 11 701
栀梦
栀梦 2020-12-02 12:36

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, Whene

相关标签:
11条回答
  • 2020-12-02 13:01

    Use this Code Its Working

    in Xml

    android:singleLine="false"
    android:overScrollMode="always"
    android:scrollbarStyle="insideInset"
    android:scrollbars="vertical"
    

    in Pragraming

    et_feedback.setOnTouchListener(new View.OnTouchListener() {
    
                public boolean onTouch(View view, MotionEvent event) {
    
                    if (view.getId() == R.id.et_feedback) {
                        view.getParent().requestDisallowInterceptTouchEvent(true);
                        switch (event.getAction() & MotionEvent.ACTION_MASK) {
                            case MotionEvent.ACTION_UP:
                                view.getParent().requestDisallowInterceptTouchEvent(false);
                                break;
                        }
                    }
                    return false;
                }
            });
    
    0 讨论(0)
  • 2020-12-02 13:03
    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;
            }
    
    
        });
    
    0 讨论(0)
  • 2020-12-02 13:04
    • You have set ScrollView as your parent most layout. That's reason your whole layout gets scrolled.
    • As, far as your EditText is concerned, you have used android:scrollbars = "vertical" which means if the EditText grows a vertical srollBar will appear. You will get the scrollbar and scrolling effect only if edittext has data high enough..

    Hope this helps...

    0 讨论(0)
  • 2020-12-02 13:08
    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >
    

    This will make your entire layout scrollable.

    For setting your edittext scrollable add android:scrollbars="vertical" to your edittext

    In your code its already written

    <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" >
    

    Remove the from code.It will work fine

    0 讨论(0)
  • 2020-12-02 13:09

    you should use NestedScrollView class. This class support child scrolling inside parent scrolling. This class can be a child or a parent.

    <android.support.v4.widget.NestedScrollView         
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="#d6d8d9">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">
            <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:maxLines="512"
                    android:text=" your content"/>
            <android.support.v4.widget.NestedScrollView
                android:layout_below="@id/ll_button"
                android:layout_width="match_parent"
                android:layout_height="300dp"
                android:background="#d6d8d9">
    
                <EditText
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content" 
                    android:text="your content"
                    android:maxLines="512"/>    
            </android.support.v4.widget.NestedScrollView>       
        </LinearLayout>
    
    </android.support.v4.widget.NestedScrollView> 
    
    0 讨论(0)
提交回复
热议问题