My Recyclerview item occupies the whole screen height and width.
I wish to implement a custom scroll inside the Recyclerview such that it scrolls only one item at a time ( similar to News In Shorts app ).
Thanks in advance!!
You need to add just two below Lines
RecylerView mRecylerView = (RecylerView).findViewById(R.id.mRecylerView)
SnapHelper mSnapHelper = new PagerSnapHelper();
mSnapHelper.attachToRecyclerView(mRecylerView);
SnapHelper can be used to snap the child to any imaginary point or any pixel on the screen
Try this code
parentScrollView.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
findViewById(R.id.childScrollView).getParent().requestDisallowInterceptTouchEvent(false);
return false;
}
});
childScrollView.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;
}
});
Related
I have a listview with a padding top. I need to detect when the empty space on top is clicked.
I tried OnClickLister but I cannot use it on ListView. OnItemClickListener works only when I click on a row.
you can add header with nothing in it to listView and set onClickListener for that header
Use a Space with a listener attached on it instead of padding. Or add a listener to the parent view and look for that event.
You can use OnTouchListener and check if the Y coordinate of the MotionEvent is less than your padding :
listView.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View view, MotionEvent motionEvent) {
switch (motionEvent.getAction()) {
case MotionEvent.ACTION_UP :
final int padding = getResources().getDimensionPixelSize(R.dimen.listView_padding);
if (motionEvent.getY() < padding) {
// do stuff here
return true;
}
break;
}
return false;
}
});
I'm facing problems in scrolling. I've the following structure in order in my project:
1) ViewPager
2) RecyclerView
3) ExpandableListView
I cannot scroll the ExpandableListView; but I can scroll RecyclerView. I tried setNestedScrolling but i didn't work.
Any solutions?
I think what you need to do is disable the scroll of the parent when you touch the child. So this should work
mListView.setOnTouchListener(new View.OnTouchListener() {
#Override
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 have a ListView inside ScrollView. I can enable scroll of ListView by
listView.getParent().requestDisallowInterCeptTouchEvent(true);
But the problem is when i scroll up in listView and it reaches top it should scroll to parent view i.e. parent scroll has to work . How can i do this ? any suggestion please.
listView.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_MOVE) {
return true; // Indicates that this has been handled by you and will not be forwarded further.
}
return false;
}
});
OR
To make the View unselectable just get the view and .setClickable(false)
OR
listView.setScrollContainer(false);
You can override ScrollView class and insert these methods inside:
private boolean isScrollEnabled = true;
public void enableScroll(boolean isScrollEnabled ) {
this.isScrollEnabled = isScrollEnabled ;
}
#Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
if (isScrollEnabled) {
return super.onInterceptTouchEvent(ev);
} else {
return false;
}
}
This is the cleanest solution to achieve this. You only call scrollView.enableScroll(true) to enable scrolling or scrollView.enableScroll(false) to disable it.
I would suggest to embed your upper view i.e any viewgroup above list view into listview header. ListView has a method, listview.addHeaderView(). That way you would be able to scroll your list (Whole View) even on small size display and you don't need scrollview.
There is a list view. I wrote this to stop the scroll when the user touches the screen while scrolling:
public class OnTouchListner implements OnTouchListener{
#Override
public boolean onTouch(View v, MotionEvent event) {
if(event.getAction()==MotionEvent.ACTION_DOWN)
{
businessResultListView.smoothScrollBy(0, 0);
return true;
}
return false;
}
}
When i scroll the list down and when I touch the screen, the list view stops scrolling. But if I again try to scroll down / up, without lifting my finger from the scroll view, i am unable to scroll it.
If I take off my finger, then touch the list and then try to scroll, then I can do so.
How can I make my list scrollable after touch ?
Any help is greatly appreciated...
Give the Scroll id like scroll_home
ScrollView scroll_home;
scroll_home = (ScrollView) findViewById(R.id.scroll_event);
and on touch listview row add this function ...
this working well
v.setOnTouchListener(new OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
scroll_home.requestDisallowInterceptTouchEvent(true);
return false;
}
});
I have an UI issue like, some EditText s are there in LinearLayout ,and this linear layout is placed in scroll view . now what i want to do is edit text has large amount of data for seeing this data i have set android:scrollbars ="vertical" by this i'm able to see the scroll bar inside the edit text but the data is not scrolling. out side scrollbar is moving.how to fix this issue.
can anybody help me. Thanks in Advance.
This may help you....
parentScrollView.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;
}
});
childScrollView.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;
}
});
In your case 'parentScrollView' is your scrollView while childScrollView is your Linearlayout/EditText
Use yourEditTextView.setMovementMethod(new ScrollingMovementMethod());