1

have EditText widget along with some widgets placed in ScrollView.

I have set the property of EditText with android:scrollbars = "vertical" to enable vertical scrolling inside editText.

Now when i launched the activity, editText has focus and it shows vertical scrollbars for some seconds.

The issue here is when i try to scroll within EditText, ScrollView moves.

How to enable scrolling within EditText and not within scrollview.

<ScrollView android:id="@+id/scrollView1" android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:id="@+id/main" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" > . . . <EditText android:id="@+id/smset" android:layout_width="match_parent" android:gravity="top|left" android:height="100dip" android:inputType="textMultiLine" > </EditText> . . . </LinearLayout> </ScrollView> 

5 Answers 5

6

In your java file

 EditText dwEdit = (EditText) findViewById(R.id.DwEdit); dwEdit.setOnTouchListener(new OnTouchListener() { public boolean onTouch(View view, MotionEvent event) { // TODO Auto-generated method stub if (view.getId() ==R.id.DwEdit) { view.getParent().requestDisallowInterceptTouchEvent(true); switch (event.getAction()&MotionEvent.ACTION_MASK){ case MotionEvent.ACTION_UP: view.getParent().requestDisallowInterceptTouchEvent(false); break; } } return false; } }); 

In xml

 <EditText android:id="@+id/DwEdit" android:layout_width="fill_parent" android:layout_height="wrap_content" android:minLines="10" android:scrollbarStyle="insideInset" android:scrollbars="vertical" android:overScrollMode="always" android:inputType="textCapSentences"> </EditText> 
Sign up to request clarification or add additional context in comments.

Comments

2

You can't place something that can scroll inside something that scrolls, too.

Android can't say for sure which element you want to be scrolling when you touch the screen so it isn't supported at all. (ignoring some hacks which are pretty bad practice).

4 Comments

i need u help on scroll view can u help me on that
@Gaurav make a question, show what you have tried, explain your problem and use proper English (not "u" when it should be "your" etc).
i have posted this at stackoverflow.com/questions/18077726/… please help me on this
@Gaurav no. You created your question and you will get your help there. Beside that you still use sms style typing which I personally hate...
0

One such hack is:

scroll.setOnTouchListener(new OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { return true; } }); 

Note that to enable scrolling in ScrollView, you will have to run the same function, but with "return false;" instead.

Comments

0

I wouldn't say it's bad practice if done properly, but it's not something naturally expected.

I regularly put scrollable views inside something that scrolls, but you have to lock the outside layer and enable scrolling on the inside. Ideally, you should do something else, but it is possible.

You can modify ScrollView to be lockable, as in here.

Then programatically lock LockableScrollView scrolling when the internal thing is touched.

smset.setOnTouchListener(new OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { // Disables LockableScrollView when the EditText is touched if (event.getAction() == MotionEvent.ACTION_DOWN) { scrollView1.setScrollingEnabled(false); } // Enables LockableScrollView when the EditText is touched if (event.getAction() == MotionEvent.ACTION_UP) { scrollView1.setScrollingEnabled(true); } return false; } }); 

The downside of this is that it will disable scrolling when the EditText is touched, but it shouldn't cause any other side-effects.

Comments

0

In kotlin, you can write an extension function for all ExitTextViews and use them everywhere :

fun EditText.setTouchForScrollBars() { setOnTouchListener { view, event -> view.parent.requestDisallowInterceptTouchEvent(true) when (event.action and MotionEvent.ACTION_MASK) { MotionEvent.ACTION_UP -> view.parent.requestDisallowInterceptTouchEvent(false) } false } } 

but add these lines in your EditTextView XML too:

android:scrollbarStyle="insideInset" android:scrollbars="vertical" android:overScrollMode="always" android:inputType="textMultiLine" 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.