Horizontal ImageSlider in Horizontal Recyclerview does not work - android

I have a horizontal recyclerview that takes up the entire screen. Within that recyclerview is a textview and an imageslider than holds three images.
I used this for the imageslider:
https://github.com/denzcoskun/ImageSlideshow
Recyclerview XML
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/bonus_detail_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:listitem="#layout/bonus_detail_item"/>
Bonus Detail XML
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/bonus_detail_title"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintHeight_percent="0.07"
android:background="#color/myOrange"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:textAlignment="center"
android:autoSizeMaxTextSize="100sp"
android:autoSizeMinTextSize="10sp"
android:autoSizeTextType="uniform"
android:layout_gravity="center_horizontal"
android:textColor="#android:color/white"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toTopOf="#id/bonus_image_slider"/>
<com.denzcoskun.imageslider.ImageSlider
android:id="#+id/bonus_image_slider"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:iss_auto_cycle="false"
app:iss_period="1000"
app:iss_delay="0"
app:iss_placeholder="#drawable/placeholder"
app:layout_constraintBottom_toBottomOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
The problem is that when I try to swipe on the imageslider the entire recyclerview scrolls. I have searched here trying to find a solution, but the option suggested on many other posts does not work for me.
holder.imageSlider.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
v.getParent().requestDisallowInterceptTouchEvent(true);
return false;
}
});
I am not restricted to using the imageSlider, but I do have to maintain the horizontal recyclerview and a horizontal swipe between images. I also tried adding the images in a horizontalscrollview, but I have been unable to set the images to be the full screen width.

You have to request disallow intercepting touch events on your RecyclerView not the direct parent of your ImageSlider which is ConstraintLayout:
holder.imageSlider.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
v.getParent() // ConstraintLayout
.getParent() // RecyclerView
.requestDisallowInterceptTouchEvent(true);
return false;
}
});

Related

Vertical RecyclerView reacts to scroll on nested Horizontal RecyclerView

In my activity, I have ViewPager consisting of fragments. I have disabled swipe motion on ViewPager using CustomViewPager.
My fragment layout has Vertical RecyclerView and inside this RecyclerView there are multiple Horizontal RecyclerViews.
To ensure that my AppBarLayout responds to scroll behaviour properly, I have programmatically set nestedScrollingEnabled to false on each Horizontal RecyclerView.
P.S. I'm using recylerview version 25.4.0
The problem is as you can see in gif attached above, to scroll horizontal recyclerview the touch should be perfectly sideways, even for a slightly slant motion on horizontal recyclerview, the vertical recyclerview picks up that event and scrolls the page vertically UP & DOWN. How to resolve this?
CustomViewPager.java
public class CustomViewPager extends ViewPager {
private boolean enabled;
public CustomViewPager(Context context, AttributeSet attrs) {
super(context, attrs);
this.enabled = true;
}
#Override
public boolean onTouchEvent(MotionEvent event) {
if (this.enabled) {
return super.onTouchEvent(event);
}
return false;
}
#Override
public boolean onInterceptTouchEvent(MotionEvent event) {
if (this.enabled) {
return super.onInterceptTouchEvent(event);
}
return false;
}
public void setPagingEnabled(boolean enabled) {
this.enabled = enabled;
}
}
Fragment Layout
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerview_productoverview"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/windowBackground"/>
Layout of items inside recyclerview_productoverview(Vertical RecyclerView)
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.constraint.ConstraintLayout
android:id="#+id/layout_section_header"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="0dp"
android:background="#ebedff"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent">
<experttag.nurserylive.util.ui.widget.WhitneySemiBoldTextView
android:id="#+id/textview_item_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="TOP FEATURED"
android:textColor="#3f4266"
android:textSize="16sp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginBottom="16dp"
app:layout_constraintVertical_bias="0.19"
android:layout_marginLeft="16dp"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginRight="16dp"
app:layout_constraintRight_toRightOf="parent"/>
<experttag.nurserylive.util.ui.widget.WhitneySemiBoldTextView
android:id="#+id/textview_item_viewall"
style="#style/AppTheme.TextLink"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#3f4266"
android:text="#string/btn_view_all_caps"
android:layout_marginRight="16dp"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBaseline_toBaselineOf="#+id/textview_item_name"/>
</android.support.constraint.ConstraintLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerview_item_section"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#+id/layout_section_header"/>
</android.support.constraint.ConstraintLayout>
Horizontal RecyclerView: #id/recyclerview_item_section
Solved this using BetterRecyclerView
see demo
read explanation
BetterRecyclerView.java

Scrolling is not working when I set GestureListener to ScrollView

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"

RecyclerView inside ScrollView - ScrollView doesn't work [duplicate]

This question already has answers here:
RecyclerView inside ScrollView is not working
(26 answers)
Closed 6 years ago.
I'm using the latest support design (compile 'com.android.support:design:+') which from 23.2 should have fixed the issue with RecyclerView inside ScrollView.
The RecyclerView and the ExpandableListView scrolling both work perfectly.
But when the ExpandableListView is too long and I want to be able to scroll the layout upwards so I could see the rest of it, the scrollview just doesn't work.
fragment :
myRecyclerView = (RecyclerView) view.findViewById(R.id.myRecyclerView);
myRecyclerView.setNestedScrollingEnabled(false);
LinearLayoutManager layoutManager = new LinearLayoutManager( mContext, LinearLayoutManager.HORIZONTAL, false );
layoutManager.setAutoMeasureEnabled(true);
myRecyclerView.setLayoutManager(layoutManager);
MyListAdapter myListAdapter = new MyListAdapter(recyclerDataList, getActivity());
myRecyclerView.setAdapter(myListAdapter);
xml:
<ScrollView
android:id="#+id/scrollView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:fillViewport="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<TextView
android:id="#+id/headerText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="header text"
android:layout_marginRight="10dp"/>
<android.support.v7.widget.RecyclerView
android:id="#+id/myRecyclerView"
android:layout_below="#id/headerText"
android:scrollbars="none"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<ExpandableListView
android:id="#+id/expandableList"
android:layout_below="#id/myRecyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="1dp"
android:dividerHeight="0dp"
android:groupIndicator="#null"
android:listSelector="#android:color/transparent"
android:showDividers="middle" >
</ExpandableListView>
</RelativeLayout>
</ScrollView>
You need to calculate listview height at run time, can not use listview or expendable listview inside scroll view like this.
Android list view inside a scroll view
You should do this way:
Implement OnItemTouchListener of RecyclerView and disallow parent touch event on ACTION_MOVE.
recyclerView.addOnItemTouchListener(new RecyclerView.OnItemTouchListener() {
#Override
public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) {
int action = e.getAction();
switch (action) {
case MotionEvent.ACTION_DOWN:
recyclerView.getParent().requestDisallowInterceptTouchEvent(true);
break;
case MotionEvent.ACTION_UP:
recyclerView.getParent().requestDisallowInterceptTouchEvent(false);
break;
case MotionEvent.ACTION_MOVE:
recyclerView.getParent().requestDisallowInterceptTouchEvent(true);
break;
}
return false;
}
#Override
public void onTouchEvent(RecyclerView rv, MotionEvent e) {
}
#Override
public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) {
}
});
Hope this will help you.

Start outSide scroll after edittext scroll finished

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;
}
});

How to catch RelativeLayout pressed state in Android?

I have Relative Layout with two TextViews inside.
How I can change text color TextViews, when RelativeLayout is pressed?
I tried used selectors, but Relative Layout don't support text color attribute.
Also a tried catch Relative Layout pressed state with OnFocus and OnTouch Listeners, but they don't working(OnFocusChangeListener) or working in one side(OnTouchListener).
The code:
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="243dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:background="#drawable/singup_button_selector"
android:clickable="true"
android:focusable="true"
android:gravity="center"
android:id="#+id/sungup"
android:textColor="#drawable/singup_button_text_selector"
android:focusableInTouchMode="true">
<TextView
android:id="#+id/singupTV1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="#string/singup"
android:textColor="#3c5775"/>
<TextView
android:id="#+id/singupTV2"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_below="#+id/singupTV1"
android:layout_marginTop="15dp"
android:gravity="center"
android:text="#string/singup_extended"
android:textColor="#506378"
android:textSize="15dp" />
</RelativeLayout>
You can set an onClickListener on the RelativeLayout, then in the onClick method, change the text colors in both TextViews in your code.
What worked for me was setting an OnTouchListener.
setOnTouchListener(new OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event)
{
if(event.getAction() == MotionEvent.ACTION_DOWN || event.getAction() == MotionEvent.ACTION_MOVE) {
// focus in
} else{
// focus out
}
return false;
}
});

Categories

Resources