Edittext scrolling inside Recyclerview and NestedScrollView android - android

I have an edittext which is of inputType textMultiLine inside RecyclerView which again is in NestedScrollView. I have a functionality in which I have to take Recyclerview inside the NestedScrollview. RecyclerView scrolling has been disabled by NestedScrollingEnabled as false. Inside this Recyclerview, there is an itemtype which has edittext in it. This edittext is Multiline and of 100 dp, If vertically, the content won't fit, the content will get cut, cause of max height. So How can I make my edittext scrollable inside Nested Scroll View
I have enabled Edittext scrolling with the following code:
<EditText
android:id="#+id/etYesDescription"
style="#style/EditTextStyle"
android:layout_width="match_parent"
android:layout_height="100dp"
android:inputType="textMultiLine"
android:imeOptions="actionDone"
android:overScrollMode="always"
android:scrollbarStyle="insideInset"
android:scrollbars="vertical" />
But it is still not scrollable, How can I make my Edittext scroll work?

You can achieve by this programmatically have look
EditText etYesDescription= (EditText) findViewById(R.id.etYesDescription);
etYesDescription.setOnTouchListener(new OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
if (v.getId() == R.id.comment1) {
v.getParent().requestDisallowInterceptTouchEvent(true);
switch (event.getAction() & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_UP:
v.getParent().requestDisallowInterceptTouchEvent(false);
break;
}
}
return false;
}
});
Hope it will help you!!

Related

Make layout unscrollable when GestureOverlayView is touched

In FragmentA, I have a scrollable layout. Inside the layout, I have
GestureOverlayView.
<android.gesture.GestureOverlayView
android:id="#+id/signGesture"
android:layout_width="match_parent"
android:layout_height="200dp"
android:background="#android:color/white"
android:fadeEnabled="false"
android:fadeOffset="10000"
android:gestureColor="#color/black"
android:gestureStrokeLengthThreshold="0.1"
android:gestureStrokeType="multiple"
android:orientation="vertical">
Is there a way to make the layout unscrollable when GestureOverlayView is touched ? I can't draw anything because the layout is moving !
You should use OnGesturePerformedListener on your gesture view and there you disable your scrollView scrolling by returning true on the touch listener
gesture.addOnGesturePerformedListener(new OnGesturePerformedListener() {
public void onGesturePerformed(GestureOverlayView v, Gesture g) {
mScrollView.setOnTouchListener( new OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event)
{
return true;
}
});
}
});
EDIT
You can take a look at this answer , it actually present a custom ScrollView that will intercept the scroll touch and disable it when you perform gesture listener.

How to disable scrolling in HorizontalScrollView?

What i want in pictures:
On the words: i want to disable scrolling with formatting text inside HorizontalScrollView.
Part of XML:
<ScrollView
android:id="#+id/review_scrollview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbars="horizontal"
android:fillViewport="true"
android:layout_marginTop="10dp">
<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/tt_review_content"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Some long text"
android:scrollHorizontally="true"/>
</HorizontalScrollView>
</ScrollView>
Method(doesn't works):
private void setTtAreaWrapContent(boolean value) {
ViewGroup.LayoutParams params = textField.getLayoutParams();
if(value) { // Wrap content
textField.setWidth(scrollView.getWidth());
} else { // Scroll
params.width = ViewGroup.LayoutParams.WRAP_CONTENT;
}
textField.setLayoutParams(params);
}
There is a very simple way to do this.
Check if the user wants to scroll or not and then store it in a boolean variable, shouldScroll.
Now do this in onCreate,
HorziontalScrollView scrollView= (HorizontalScrollView)findViewById(R.id.scrollView);
if(!shouldScroll)
scrollView.setOnTouchListener(new OnTouch());
You also need to define a class OnTouch extending the OnTouchListener
private class OnTouch implements OnTouchListener
{
#Override
public boolean onTouch(View v, MotionEvent event) {
return true;
}
}
Now for the TextView formatting, just use android:singleLine="false" or use android:width="0dip"
I had absolutely the same need for code, so I initially proposed a ViewSwitcher with the same layouts, but one with HorizontalScrollView and one without it. And switch to the corresponding view depending on the setting.
However, I found an easier solution. After recreation of the Activity (when wrapping settings are changed by the user), use the code in the onCreate methode:
if (isWrapContent)
{
View mTV = findViewById(R.id.my_text_view);
HorizontalScrollView myHSV = (HorizontalScrollView) findViewById(R.id.my_hsv);
ViewGroup parent = (ViewGroup) myHSV.getParent();
ViewGroup.LayoutParams params = myHSV.getLayoutParams();
int index = parent.indexOfChild(myHSV);
myHSV.removeAllViews();
parent.removeView(myHSV);
parent.addView(mTV, index, params);
}
You need to use your id's and variables correspondingly.
It will remove the horizontal scrollview with the embedded textview and then reinsert the textview.
My answer provides direct and valid answer on how the asked issue could be resolved instead of freezing the horizontal scrollview or wondering about the point of the question, as it is done in the other comments and answers.

scrolling jerky before braking when single edittext inside scrollview

I'm writing a simple text editor in my app. Accordingly, I need to scroll through a large editable text.
My layout:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/scroll"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<EditText
android:id="#+id/note"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/black"
android:padding="5dp"
android:textSize="14sp"/>
</ScrollView>
In my Activity I set large text :
public class FileEditorActivity extends Activity {
private EditText text;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_file_editor);
text = (EditText)findViewById(R.id.note);
text.setText(newText); ////// LARGE TEXT
}
}
Now, text scrolls but when the scroll speed is reduced scrolling starts to twitch (jerky)!!!!!!
I thought why so ......... And try the following :
scrollView = (ScrollView)findViewById(R.id.scroll);
scrollView.setDescendantFocusability(ViewGroup.FOCUS_BEFORE_DESCENDANTS);
scrollView.setFocusable(true);
scrollView.setFocusableInTouchMode(true);
scrollView.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
v.requestFocusFromTouch();
if (text.hasFocus()) {
text.clearFocus();
}
return false;
}
});
And after that (when edittext always lost focus before scrolling) scroll large text working perfect when the scroll speed is reduced.
But I need to always stay in focus and maintain the state of the cursor when scrolling text ((((
How to do it ?????????
P.S. I want to like this :
ES Explorer app
When open text file on edit
Thanks in advance !!!!

EditText scroller and ScrollView

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

android-How to put scroll view under scroll view

My application need to 2 scroll views(sv1,sv2). sv1 is main scroll view and sv2 is sub scroll view of sv1.
is it possible? then how to do it.
Following one is my answer. it is working in simulator only but not working in device means device support sv1 only sv2 is not working.
How to do it?
thanks
<ScrollView android:id=”#+id/parent_scroll”
android:layout_width=”fill_parent”
android:layout_height=”wrap_content”
android:layout_weight=”1″
android:background=”#drawable/dotted_bg”
android:focusableInTouchMode=”false”>
<LinearLayout />
<LinearLayout />
<LinearLayout >
<ScrollView android:id=”#+id/child_scroll”
android:layout_width=”fill_parent”
android:layout_height=”fill_parent”
android:background=”#drawable/text_box_bg”>
<TextView android:id=”#+id/text_description”
android:layout_width=”fill_parent”
android:layout_height=”fill_parent”
android:textColor=”#color/gray”
android:textSize=”12dip”
android:padding=”5dip”
android:scrollbars=”vertical”/>
<!–ScrollView>
</LinearLayout>
Step 1 : Provide unique id to both the scrollview.
Step 2 : get reference of that two scrollview in your activity.
parentScroll=(ScrollView)findViewById(R.id.parent_scroll);
childScroll=(ScrollView)findViewById(R.id.child_scroll);
Step 3: Now set touch listeners for both.
parentScroll.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
Log.v(TAG,”PARENT TOUCH”);
findViewById(R.id.child_scroll).getParent().requestDisallowInterceptTouchEvent(false);
return false;
}
});
childScroll.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event)
{
Log.v(TAG,”CHILD TOUCH”);
// Disallow the touch request for parent scroll on touch of child view
v.getParent().requestDisallowInterceptTouchEvent(true);
return false;
}
});
Done …

Categories

Resources