第二个recyclerview滚动不流畅

时间:2019-10-29 13:36:25

标签: android android-recyclerview

我正在用两个在约束布局中彼此平行的回收器视图在android中实现一个底层表。第一个回收者视图平滑滚动,但是第二个视图不滚动或多次滑动后仍滚动。 我想平滑滚动两个回收站视图。Here is the screenshot of recycler views in bottom sheet

这是我的 xml 代码:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/white">


    <androidx.constraintlayout.widget.Guideline
        android:id="@+id/leftGuideline"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:orientation="vertical"
        app:layout_constraintGuide_percent="0.05" />

    <androidx.constraintlayout.widget.Guideline
        android:id="@+id/leftInnerGuideline"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:orientation="vertical"
        app:layout_constraintGuide_percent="0.03" />
    <androidx.constraintlayout.widget.Guideline
        android:id="@+id/rightInnerGuideline"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:orientation="vertical"
        app:layout_constraintGuide_percent="0.97" />


    <androidx.constraintlayout.widget.Guideline
        android:id="@+id/rightGuideline"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:orientation="vertical"
        app:layout_constraintGuide_percent="0.95" />

    <androidx.constraintlayout.widget.Guideline
        android:id="@+id/centerGuideline"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:orientation="vertical"
        app:layout_constraintGuide_percent="0.65" />

    <androidx.constraintlayout.widget.Guideline
        android:id="@+id/bottomGuideline"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:orientation="horizontal"
        app:layout_constraintGuide_percent="1" />


    <ImageView
        android:id="@+id/topBackground"
        android:layout_width="0dp"
        android:layout_height="80dp"
        android:background="@color/gray"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:id="@+id/pickText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Pick Up"
        android:textColor="@color/blue"
        android:textSize="30sp"
        app:layout_constraintBottom_toTopOf="@id/selectedDate"
        app:layout_constraintStart_toEndOf="@id/leftGuideline"
        app:layout_constraintTop_toTopOf="@id/topBackground" />

    <TextView
        android:id="@+id/selectedDate"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Tomorrow, Between 11:00am - 12:00pm"
        android:textColor="@color/black"
        android:textSize="15sp"
        app:layout_constraintBottom_toBottomOf="@id/topBackground"
        app:layout_constraintStart_toEndOf="@id/leftGuideline"
        app:layout_constraintTop_toBottomOf="@id/pickText" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Done"
        app:layout_constraintBottom_toBottomOf="@id/selectedDate"
        app:layout_constraintEnd_toEndOf="@id/rightGuideline"
        app:layout_constraintTop_toTopOf="@id/pickText" />

    <ImageView
        android:id="@+id/separator"
        android:layout_width="0dp"
        android:layout_height="2dp"
        android:background="@color/blue"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@id/topBackground" />


    <androidx.recyclerview.widget.RecyclerView
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:id="@+id/timeRecyclerView"
        android:clipToPadding="false"
        android:paddingBottom="60dp"
        app:layout_constraintBottom_toBottomOf="@id/bottomGuideline"
        app:layout_constraintEnd_toEndOf="@id/centerGuideline"
        app:layout_constraintStart_toStartOf="@id/leftInnerGuideline"
        app:layout_constraintTop_toBottomOf="@id/separator"
        />

    <androidx.recyclerview.widget.RecyclerView
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:clipToPadding="false"
        android:paddingBottom="60dp"
        android:id="@+id/daysRecyclerView"
        app:layout_constraintBottom_toBottomOf="@id/bottomGuideline"
        app:layout_constraintStart_toStartOf="@id/centerGuideline"
        app:layout_constraintEnd_toEndOf="@id/rightInnerGuideline"
        app:layout_constraintTop_toBottomOf="@id/separator"
        />

    <TextView
        android:layout_width="0dp"
        android:layout_height="500dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />


</androidx.constraintlayout.widget.ConstraintLayout>

这是我的 java 类:

public class BottomSheet extends BottomSheetDialogFragment {


    RecyclerView timeRecyclerView, daysRecyclerView;


    private ArrayList<DaysModal> daysModalArrayList;
    private DaysAdapter adapter;

    private String[] day = new String[]{"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"};
    private String[] date = new String[]{"21 Oct", "22 Oct", "23 Oct", "24 Oct", "25 Oct", "26 Oct", "27 Oct"};
    private int[] background = new int[]{R.drawable.white_shadow, R.drawable.white_shadow, R.drawable.white_shadow, R.drawable.white_shadow, R.drawable.white_shadow, R.drawable.white_shadow, R.drawable.white_shadow};


    private ArrayList<TimeModal> timeModalArrayList;
    private TimeAdapter timeAdapter;

    private String[] time = new String[]{
            "08:00am - 09:00am", "09:00am - 10:00am", "10:00am - 11:00am",
            "11:00am - 12:00pm", "12:00pm - 01:00pm", "01:00pm - 02:00pm",
            "02:00pm - 03:00pm", "03:00pm - 04:00pm", "04:00pm - 05:00pm",
            "05:00pm - 06:00pm", "06:00pm - 07:00pm", "07:00pm - 08:00pm"
    };
    private int[] timeBackground = new int[]{
            R.drawable.white_shadow, R.drawable.white_shadow,
            R.drawable.white_shadow, R.drawable.white_shadow,
            R.drawable.white_shadow, R.drawable.white_shadow,
            R.drawable.white_shadow, R.drawable.white_shadow,
            R.drawable.white_shadow, R.drawable.white_shadow,
            R.drawable.white_shadow, R.drawable.white_shadow
    };


    String selectedButton;

    public static BottomSheet getInstance() {
        return new BottomSheet();
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

        final View view = inflater.inflate(R.layout.bottom_sheet, container, false);
        selectedButton = this.getArguments().getString("selectedButton");
        daysRecyclerView = view.findViewById(R.id.daysRecyclerView);
        timeRecyclerView = view.findViewById(R.id.timeRecyclerView);
        timeModalArrayList = displayTimes();
        timeAdapter = new TimeAdapter(getActivity(), timeModalArrayList);
        timeRecyclerView.setAdapter(timeAdapter);
        timeRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity(), RecyclerView.VERTICAL, false));


        daysModalArrayList = displayDays();
        adapter = new DaysAdapter(getActivity(), daysModalArrayList);
        daysRecyclerView.setAdapter(adapter);
        daysRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity(), RecyclerView.VERTICAL, false));



        return view;
    }


    private ArrayList<DaysModal> displayDays() {
        ArrayList<DaysModal> list = new ArrayList<>();
        for (int i = 0; i < date.length; i++) {
            DaysModal daysModal = new DaysModal();
            daysModal.setDayOfTheWeek(day[i]);
            daysModal.setDate(date[i]);
            daysModal.setBackground(background[i]);
            list.add(daysModal);
        }
        return list;
    }


    private ArrayList<TimeModal> displayTimes() {
        ArrayList<TimeModal> list = new ArrayList<>();
        for (int i = 0; i < time.length; i++) {
            TimeModal timeModal = new TimeModal();
            timeModal.setTime(time[i]);
            timeModal.setBackground(timeBackground[i]);
            list.add(timeModal);
        }
        return list;
    }
}

0 个答案:

没有答案