0

I had a problem in offset scrolling, I want when I scroll up, I'll get the next up item and the same for down items. I display every item in the middle view so I get the offset like the height of the view, but when I scroll it gives me last item or the first item. I tried scrollTo() and the same problem

I did this but it's not working.

public void fillFormules(List<Category> objectsTextToShow)
{
    MyRecyclerAdapter adapter;
    final LinearLayout layoutItemDetail = (LinearLayout) view.findViewById(R.id.middle);
    LinearLayout relativeLayout = (LinearLayout) view.findViewById(R.id.titles);


    // Initialize recycler view
    for (int j = 0; j <objectsTextToShow.size() ; j++) {
        LinearLayout parentLayout = new LinearLayout(getActivity());
        parentLayout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, (float) 1.0));
        parentLayout.setOrientation(LinearLayout.HORIZONTAL);
        RecyclerView mRecyclerView = new RecyclerView(getActivity()); //(RecyclerView) view.findViewById(R.id.recycler_view);
        List<Item> items = new ArrayList<Item>();
        TextView textCat = new TextView(getActivity());
        textCat.setText(Check.Languages(objectsTextToShow.get(j).getName(), LANGUAGE_ID));
        textCat.setTextSize(28);
        textCat.setLayoutParams(new TableLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, 1f));
        textCat.setTextColor(colorUtils.TITLE);
        textCat.setGravity(Gravity.CENTER);

        relativeLayout.addView(textCat);
        textCat.setBackgroundColor(colorUtils.backgroundColor);

        for (int i = 0; i <objectsTextToShow.get(j).getItems().size() ; i++) {
            items.add(objectsTextToShow.get(j).getItems().get(i));
        }

        final LinearLayoutManager manager = new LinearLayoutManager(getActivity());
        manager.setOrientation(LinearLayoutManager.VERTICAL);
        mRecyclerView.setLayoutManager(manager);
        adapter = new MyRecyclerAdapter(getActivity(), items);
        mRecyclerView.setAdapter(adapter);
        parentLayout.addView(mRecyclerView);
        layoutItemDetail.addView(parentLayout);

        mRecyclerView.setOnScrollListener(new RecyclerView.OnScrollListener() {

            @Override
            public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                super.onScrolled(recyclerView, dx, dy);

                final int Height = layoutItemDetail.getHeight();
                if(dy > 0)
                {
                    Log.e("RecyclerView scrolled: ", "scroll up!"+Height);
                    recyclerView.smoothScrollToPosition(Height);
                }
                else
                {
                    recyclerView.smoothScrollToPosition(-Height);

                Log.e("RecyclerView scrolled: ", "scroll down!"+-Height);

                }

            }
        });

    }
}

pic :enter image description here

NizarETH
  • 969
  • 3
  • 15
  • 38

0 Answers0