I'm trying to achieve to scroll views in xml layout which contain recycleview and viewpager but somehow nestedScrollView is not scrolled up the views.
layout file.
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipe_refresh"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<android.support.v4.widget.NestedScrollView
android:id="@+id/nested_scroll"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:fillViewport="true"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="@dimen/dimen_200">
<android.support.v4.view.ViewPager
android:id="@+id/viewpager_media"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<RelativeLayout
android:id="@+id/viewPagerIndicator"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="center"
android:padding="@dimen/dimen_10">
<LinearLayout
android:id="@+id/viewPagerCountDots"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:gravity="center"
android:orientation="horizontal" />
</RelativeLayout>
</RelativeLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/rc_media"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.v4.widget.SwipeRefreshLayout>
Java file
mediaAdapter = new MediaDiscoverAdapter(getActivity(), mediaCallbackListener);
discoverBinding.rcMedia.setNestedScrollingEnabled(false);
discoverBinding.nestedScroll.setFillViewport(true);
discoverBinding.rcMedia.setAdapter(mediaAdapter);
layoutManager = new StickyHeaderLayoutManager();
layoutManager.setAutoMeasureEnabled(true);
discoverBinding.rcMedia.setLayoutManager(layoutManager);
I figure out the solution with the help of StackOverFlow. I just make Viewpager
part of RecycleView
as row item using getItemViewType
and removed the NestedScrollView
so now layout looks like..
mainLayout.xml
<data>
<variable
name="MediaDiscoverFragmentNew"
type="com.hpc.fragments.media.MediaDiscoverFragmentNew" />
</data>
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipe_refresh"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<android.support.v7.widget.RecyclerView
android:id="@+id/rc_media"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.v4.widget.SwipeRefreshLayout>
and created two separate item xmls raw_media_top.xml for top Viewpager
and another raw_media.xml for rest of items.
if(viewType == HEADER_VIEW) { RawMediaTopBinding mediaTopBinding = DataBindingUtil.inflate(mLayoutInflater, R.layout.raw_media_top, parent, false); mediaTopBinding.setMediaDiscoverAdapterNew(this); return new HeaderViewHolder(mediaTopBinding); } else { RawMediaBinding inspirationItemsBinding = DataBindingUtil.inflate(mLayoutInflater, R.layout.raw_media, parent, false); inspirationItemsBinding.setMediaDiscoverAdapterNew(this); return new ItemViewHolder(inspirationItemsBinding); }
Cheers!