我试图在xml布局中滚动视图,其中包含recycleview和viewpager,但不知道nestedScrollView不会向上滚动视图。
布局文件。
export
Java文件
<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>
答案 0 :(得分:0)
我在StackOverFlow的帮助下找出了解决方案。我只使用Viewpager
将RecycleView
getItemViewType
部分作为行项目,并删除了NestedScrollView
,所以现在布局看起来像..
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>
为顶级Viewpager
创建了两个单独的项目xmls raw_media_top.xml ,为其余项目创建了另一个 raw_media.xml 。
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); }
干杯!