I have ViewPager2
with 3 Fragments and all has recyclerview
but in Middle fragment recyclerview not scrolling if i try to touch recyclerview Items but it scroll smoothly if i touch right or left side of recycler as you can see in image.
View Pager Layout
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<com.google.android.material.tabs.TabLayout
android:id="@+id/tabItemes"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabGravity="center"
android:clipToPadding="true"
app:tabPaddingBottom="0dp"
app:tabPaddingEnd="0dp"
app:tabPaddingStart="0dp"
app:tabPaddingTop="0dp"
app:tabIndicatorHeight="0dp"
app:tabMode="fixed"
app:tabTextColor="@color/black"
app:tabSelectedTextColor="@color/primary"
app:tabIndicatorColor="@color/primary_light">
<com.google.android.material.tabs.TabItem
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="About" />
<com.google.android.material.tabs.TabItem
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Media" />
<com.google.android.material.tabs.TabItem
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Connections" />
</com.google.android.material.tabs.TabLayout>
<androidx.viewpager2.widget.ViewPager2
android:id="@+id/profileViewPager"
android:orientation="horizontal"
android:nestedScrollingEnabled="true"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
ViewPager2 Setup
userInfo_ViewPager = view.findViewById(R.id.profileViewPager);
userInfo_ViewPager.setOffscreenPageLimit(1);
userProfile_tabAdapter = new UserProfile_TabAdapter(getChildFragmentManager(), getLifecycle());
TabLayout tabLayout = view.findViewById(R.id.tabItemes);
Media Fragment Layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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="match_parent"
android:isScrollContainer="true"
android:nestedScrollingEnabled="true"
android:orientation="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<TextView
android:id="@+id/seeAllPhotos"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dp"
android:textSize="12sp"
android:textStyle="bold"
android:text="See All"
/>
<com.elaxer.CustomClass.RotateLoading
android:id="@+id/rotateloading"
android:layout_width="80dp"
android:layout_height="80dp"
app:loading_color="@color/greenElaxer"
android:layout_gravity="center_horizontal|center_vertical"
app:loading_speed="11"
app:loading_width="5dp" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/userPhotos_recycler"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingEnd="10dp"
android:paddingStart="10dp"
tools:listitem="@layout/recycler_view_item_8"
tools:spanCount="5"
tools:layoutManager="GridLayoutManager" />
</LinearLayout>
Media Fragment
public class UserPhoto_fragment extends Fragment {
RecyclerView photosRecycler;
StaggeredGridLayoutManager layoutManager;
List<UserGrid> ImageList;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
View view=inflater.inflate(R.layout.userprofile_photos,container,false);
photosRecycler=view.findViewById(R.id.userPhotos_recycler);
seeAllPhotos = view.findViewById(R.id.seeAllPhotos);
StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
layoutManager.setGapStrategy(StaggeredGridLayoutManager.GAP_HANDLING_NONE);
ImageList=new ArrayList<>();
photosRecycler.addItemDecoration(new SpacesItemDecoration(16));
photosRecycler.setLayoutManager(layoutManager);
photosRecycler.setHasFixedSize(true);
adapter=new fetchPhoto_Adapter();
photosRecycler.setAdapter(adapter);
return view;
}
public class fetchPhoto_Adapter extends RecyclerView.Adapter<fetchPhoto_Adapter.ViewHolder>{
@NonNull
@Override
public fetchPhoto_Adapter.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
LayoutInflater inflater= (LayoutInflater) viewGroup.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = inflater.inflate(R.layout.userprofile_photogallery,viewGroup,false);
return new ViewHolder(v);
}
@Override
public void onBindViewHolder(fetchPhoto_Adapter.ViewHolder viewHolder, int i) {
UserGrid userImages = ImageList.get(i);
Glide.with(getActivity()).load(userImages.getWeb_URL()).into(viewHolder.image);
}
@Override
public int getItemCount() {
if (ImageList!=null && ImageList.size()>0){
return ImageList.size();
}else {
return 0;
}
}
public class ViewHolder extends RecyclerView.ViewHolder {
ImageView image;
public ViewHolder(View itemView) {
super(itemView);
image = itemView.findViewById(R.id.UserProfile_photoThumb);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
image.setClipToOutline(true);
}
}
}
}
private final RecyclerView.OnItemTouchListener itemTouchListener = new RecyclerView.OnItemTouchListener() {
@Override
public boolean onInterceptTouchEvent(@NonNull RecyclerView rv, @NonNull MotionEvent e) {
int action = e.getAction();
Log.d(TAG, "onInterceptTouchEvent: "+action);
if (photosRecycler.canScrollVertically(1)){
if (action == MotionEvent.ACTION_MOVE){
photosRecycler.requestDisallowInterceptTouchEvent(true);
}
return false;
}else {
if (action == MotionEvent.ACTION_MOVE){
photosRecycler.requestDisallowInterceptTouchEvent(false);
photosRecycler.removeOnItemTouchListener(this);
}
return true;
}
}
@Override
public void onTouchEvent(@NonNull RecyclerView rv, @NonNull MotionEvent e) {
}
@Override
public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) {
}
};
}
What i have already tried:
- Nested ScrollView Enable/Disable in Recyclerview and Viewpager
RecyclerView.OnItemTouchListener
Implementation to get recyclerview focus- Changed Fragment layout to constraintlayout.
I am running out of ideas and google search for solution. Can you suggest why my recyclerview is not working when i am trying to scroll by touching item and why its only working by both sides. If i miss anything to post please let me know.