问题描述
你好,我正在尝试实现一个滚动功能,一次只能滚动一个项目,我已经尝试过这个,但它不起作用
我只上传了一部分代码,如果有人想查看任何文件的完整代码,请告诉我
注意:-
我使用了交错网格布局管理器,但我不想 删除它
Java 文件
Home_Fragment.java
public class Home_Fragment extends Fragment {
private final DatabaseReference databaseReference = FirebaseDatabase.getInstance().getReference("uploads");
public List<Upload> mUploads;
PostAdapter postsAdapter;
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater,@Nullable ViewGroup container,@Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_home,container,false);
Objects.requireNonNull(getActivity()).setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
RecyclerView postRecyclerView = view.findViewById(R.id.recyclerViewHome);
// LinearSnapHelper linearSnapHelper = new SnapHelperOneByOne();
// linearSnapHelper.attachToRecyclerView(postRecyclerView);
postRecyclerView.setLayoutManager(
new StaggeredGridLayoutManager(1,StaggeredGridLayoutManager.VERTICAL)
);
getData();
mUploads = new ArrayList<>();
postsAdapter = new PostAdapter(getContext(),mUploads);
postRecyclerView.setAdapter(postsAdapter);
return view;
}
XML 文件
fragment_home.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/recyclerViewHome"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:orientation="vertical"
android:overScrollMode="never"/>
</RelativeLayout>
post_item_container.xml
<com.google.android.material.imageview.ShapeableImageView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/imagePost"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="6dp"
android:layout_marginTop="11dp"
android:layout_marginEnd="6dp"
android:contentDescription="@string/todo"
app:shapeAppearanceOverlay="@style/RoundedCorner" />
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)