Hope all of you doing well.
My Problem is:
I have xml code like following:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/activity_left_margin"
android:layout_marginRight="#dimen/activity_right_margin"
android:orientation="vertical"
android:paddingBottom="#dimen/activity_bottom_padding"
android:paddingTop="#dimen/activity_top_padding" >
<EditText
android:id="#+id/custDetailsNameEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/name_cust_all_add"
android:inputType="textPersonName"
android:textSize="#dimen/common_fontsize" />
<EditText
android:id="#+id/custDetailsDescEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:hint="#string/description_add_all_cust"
android:inputType="textMultiLine"
android:lines="5"
android:minLines="3"
android:gravity="top|left"
android:scrollbars="vertical"
android:scrollbarStyle="insideInset"
android:overScrollMode="always"
android:fadeScrollbars="false"
android:scrollbarAlwaysDrawVerticalTrack="true"
android:textSize="#dimen/common_fontsize" />
</LinearLayout>
</ScrollView>
In that i have two EditText in </ScrollView>, Second <EditText/> does not scrolling inner side. Problem is Full View is scrolled while i am scrolling but i want to also scroll vertically in second EditText when user enter more than 5 lines. In that ScrollBar is displaying but not scrolling.
How can i solve this.
Your Help would be appreciated.
This code should work.....
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findViewById(R.id.parentScrollView).setOnTouchListener(parentListener);
findViewById(R.id.custDetailsDescEditText).setOnTouchListener(childListener);
}
OnTouchListener parentListener = new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
findViewById(R.id.custDetailsDescEditText).getParent()
.requestDisallowInterceptTouchEvent(false);
return false;
}
};
OnTouchListener childListener = new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
v.getParent().requestDisallowInterceptTouchEvent(true);
return false;
}
};
Try something like this in your code
ScrollView scroller = new ScrollView(this);
EditText et=(EditText)findViewById(R.id.yourEdittext);
scroller.addView(et);
Related
I have a RecyclerView
<android.support.v7.widget.RecyclerView
android:id="#+id/activityRecicler"
android:layout_width="match_parent"
android:scrollbars="vertical"
android:layout_height="wrap_content"
app:stackFromEnd="true"
/>
And I have a row layout:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/description"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/solutions"/>
</LinearLayout>
And the wrap content work, but my problem is that TextView with id description It could be very long and so, I would have a Scroll for this TextView.
How could I do this?
Change your layout XML to:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ScrollView
android:id="#+id/scroll_view"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/description"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</ScrollView>
<TextView
android:id="#+id/solutions"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
And then in your activity:
recyclerView.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
findViewById(R.id.scroll_view).getParent().requestDisallowInterceptTouchEvent(false);
return false;
}
});
scrollView.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
// Disallow the touch request for parent scroll on touch of child view
v.getParent().requestDisallowInterceptTouchEvent(true);
return false;
}
});
I am beginner on Android and so I don't know if my solution it's good.
I have put in Layout Row as suggested by #Payal
<ScrollView
android:id="#+id/childScroll"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/solutions"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="long_text"
android:maxLines="5"
android:scrollbars="vertical"/>
</ScrollView>
And in My ViewHolder
public ViewHolder(View itemView) {
super(itemView);
solutions = (TextView) itemView.findViewById(R.id.solutions);
description = (TextView) itemView.findViewById(R.id.description);
scrollable = (ScrollView) itemView.findViewById(R.id.childScroll);
solutions.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
// Disallow the touch request for parent scroll on touch of child view
v.getParent().requestDisallowInterceptTouchEvent(true);
return false;
}
});
//Enabling scrolling on TextView.
solutions.setMovementMethod(new ScrollingMovementMethod());
}
And it's work.
I can scroll the TextView in my RecyclerView
Try below code on your textview id in viewholder.
scrollable = (TextView)findViewById(R.id.textView1);
//Enabling scrolling on TextView.
scrollable.setMovementMethod(new ScrollingMovementMethod());
add in TextViewlayout
android:scrollbars="vertical"
rowlayout.xml
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<TextView
android:id="#+id/description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:ellipsize="marquee"
android:fadingEdge="horizontal"
android:lines="1"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:singleLine="true"
android:textColor="#ff4500" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/solutions"/>
</LenearLayout>
and in activity
descrptionTextview.setSelected(true);
either you can wrap it in scrollview like this
<ScrollView
android:layout_height="100px"
android:layout_width="fill_parent">
<TextView
android:id="#+id/text_view"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="long_text"/>
</ScrollView>
or
add these two attributes to yout textview
android:maxLines="5"
android:scrollbars="vertical"
and add below line in your code
textview.setMovementMethod(new ScrollingMovementMethod());
hope this helps :)
Make a new class
public class AutoScrollingTextView extends TextView {
public AutoScrollingTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public AutoScrollingTextView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public AutoScrollingTextView(Context context) {
super(context);
}
#Override
protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) {
if (focused) {
super.onFocusChanged(focused, direction, previouslyFocusedRect);
}
}
#Override
public void onWindowFocusChanged(boolean focused) {
if (focused) {
super.onWindowFocusChanged(focused);
}
}
#Override
public boolean isFocused() {
return true;
}
}
Then in xml
<AutoScrollingTextView
android:scrollHorizontally="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"/>
This works !!!
I have a ScrollView and a nested TextView. When I set setOnTouchListener to it,the gestures are recognized but the scrolling not working. And If I set setOnTouchListener to nested TextView,its working fine. I have tried by googling but could not solve the problem.
But my need is to set the setOnTouchListener to ScrollView.
Please help.
layout.xml
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FF0000"
android:id="#+id/scrollView">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="#+id/tv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textColor="#000000"
android:background="#00FF00"
android:padding="15dp"
android:textSize="18sp" />
</LinearLayout>
</ScrollView>
MainActivity.java
mGestureDetector = new GestureDetectorCompat(this,this);
findViewById(R.id.scrollView).setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View v, final MotionEvent event) {
Log.e("Stark", "setOnTouchListener");
mGestureDetector.onTouchEvent(event);
return true;
}
});
Why you need to set onTouch. If only scroll up and down. Try below
ScrollView sv;
sv.post(new Runnable() {
#Override
public void run() {
sv.fullScroll(View.FOCUS_DOWN);
}
});
make sure you have this in scrollview xml. hope it helps.
android:fillViewport="true"
I've tried every simple examples on stackoverflow but nothing can solve my problem. Here's my question
I have ScrollView in activity and I have scrollbars="vertical" option editText inside ScrollView.
I want to scroll outside scrollview's scroll after inside edittext scroll finish, like on top of the edittext scroll or bottom of the edittext scroll
I thought that it can be done with view catchs scroll lisetener but nothing worked.
Try the below sample code hope it works for you.
In XML
<?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"
android:background="#aa8822"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#aa8822"
android:orientation="vertical" >
<EditText
android:id="#+id/edt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/white"
android:ems="10"
android:maxLines="3"
android:scrollbars="vertical"
android:textColor="#android:color/black"
android:textSize="20sp"
android:textStyle="bold" >
<requestFocus />
</EditText>
</LinearLayout>
</ScrollView>
Put some more view so the scroll view scroll works.
Now in your activity-
EditText edt = (EditText) findViewById(R.id.edt);
edt.setOnTouchListener(new OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
if (v.getId() == R.id.edt) {
v.getParent().requestDisallowInterceptTouchEvent(true);
switch (event.getAction() & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_UP:
v.getParent().requestDisallowInterceptTouchEvent(false);
break;
}
}
return false;
}
});
All,I hava a scroll contains a editText.
Once I clicks the editText ,it gets focus and a SoftInput shows.
In my mind, if I clicks the blank space , the softinput hide, and editText lose the focus, and scrollview get focus.
So my code like this:
scrollView.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
//call twice, once down, once up
if (event.getAction() == MotionEvent.ACTION_DOWN) {
if (activity.getCurrentFocus() != null && activity.getCurrentFocus().getWindowToken() != null) {
inputManager.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
scrollView.requestFocus();
activity.getCurrentFocus();
}
}
return false;
}
});
ScrollView
android:focusable="true"
android:focusableInTouchMode="true"
android:id="#+id/scrollView"
android:layout_below="#+id/topBar"
android:layout_marginTop="20dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
But after all, editText still focus(activity.getCurrentFocus() == editText), any advices?
Use LinearLayout instead of ScrollView. Or wrap EditText with LinearLayout below.
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/scrollView"
android:layout_gravity="center_horizontal" >
<LinearLayout
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/linearLayout"
android:layout_gravity="center_horizontal" >
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:ems="10"
android:id="#+id/editText" />
</LinearLayout>
</ScrollView>
Well friend ..
I have a design so:
The main Scroll is very necessary when appear the keyboard... If i dont make that, the button can't see...
The problem is when i try move inside the Edittext with the keyboard active...
I tried this:
android:scrollbars="vertical"
and this:
setMovementMethod(new ScrollingMovementMethod());
but not solve this yet
Anyone help me?
grax advance!
Check this without using scroll bar:
add permission in menifest file for corresponding activity.
android:windowSoftInputMode="adjustPan"
Please try this:
Your layout should be similar to example:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<EditText
android:id="#+id/edittext"
android:layout_width="200dp"
android:layout_height="500dp"
android:text="some long text"
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
</LinearLayout>
</ScrollView>
and in your java try this:
EditText edit = (EditText)findViewById(R.id.edittext);
edit.setOnTouchListener(new OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
if (v.getId() == R.id.edittext) {
v.getParent().requestDisallowInterceptTouchEvent(true);
switch (event.getAction() & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_UP:
v.getParent().requestDisallowInterceptTouchEvent(false);
break;
}
}
return false;
}
});
It could be helpful.