【发布时间】:2019-11-22 14:14:35
【问题描述】:
我想显示 recyclerview 的下一个和上一个项目与当前可见项目 (as in this third party library) 相比的部分。不过,我设法用我的原生 recyclerview 做到了。
这对我来说听起来很棒,现在我想将当前可见项目的高度设置为大于下一个和上一个项目的高度,如上述库的 gif 所示!
我已经设法在以下阶段使用我的代码显示下一个和上一个项目:
1.将recyclerview适配器设置为:
LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
layoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
locationTypeFragmentBinding.mRecylerview.setLayoutManager(layoutManager);
locationTypeFragmentBinding.mRecylerview.setHasFixedSize(true);
final LocationTypePictureAdapter locationTypePictureAdapter =
new LocationTypePictureAdapter(getActivity(), locationDetails,false);
final SnapHelper snapHelper = new PagerSnapHelper();
snapHelper.attachToRecyclerView(locationTypeFragmentBinding.mRecylerview);
locationTypeFragmentBinding.mRecylerview.post(new Runnable() {
@Override
public void run() {
locationTypeFragmentBinding.mRecylerview.
setAdapter(locationTypePictureAdapter);
}
});
2。我在 xml 中的 RecyclerView 是:
<android.support.v7.widget.RecyclerView
android:id="@+id/mRecylerview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/buttonsHolder"
android:clipToPadding="false"
android:orientation="horizontal"
android:padding="@dimen/_10sdp"
android:paddingStart="@dimen/_15sdp"
android:paddingEnd="@dimen/_15sdp"
android:scrollbarStyle="outsideOverlay"
android:visibility="gone"/>
3.我的 RecyclerView 项目 xml 是:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mainContainer"
android:layout_width="match_parent"
android:layout_height="@dimen/_200sdp">
<android.support.v7.widget.CardView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="@dimen/_5sdp"
android:layout_marginEnd="@dimen/_5sdp"
android:background="@android:color/transparent"
app:cardElevation="0dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/locationPicture"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
</android.support.v7.widget.CardView>
</RelativeLayout>
4.我需要实现的是: 我知道我可以使用上述库,但我想将当前可见项目的高度设置为大于要显示给用户的 recyclerview 的下一个和上一个项目。
有人可以找出我的代码做错了什么吗?
我需要的示例图片
【问题讨论】:
-
你为什么不改用
ViewPager?有很多你需要的库
标签: java android user-interface android-recyclerview