D
D
dimasik1002002018-08-15 15:42:16
Java
dimasik100200, 2018-08-15 15:42:16

How to display Recycler View in bottom sheet?

I need to create a bottom sheet with two views: a horizontal rececler view and a liner layout below it. How to do this if I implement the bottom sheet through the BottomSheetDialogFragment. I tried to declare a recyclerview there, as in normal fragments, but it is not displayed on the device during the test. How to fix it?

sheet_chat xml file code
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/chat_sheet"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/colorWhite"
    app:layout_behavior="android.support.design.widget.BottomSheetBehavior"
    android:orientation="vertical">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recycler_view_chat"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:clipToPadding="false"
        android:scrollbars="vertical"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

    </android.support.v7.widget.RecyclerView>

    <include layout="@layout/line_divider" />

    <LinearLayout . . . >

</LinearLayout>

Here is the BottomSheetDialogFragment code
public class ChatBottomSheetDialog extends BottomSheetDialogFragment {

    private ArrayList<SheetObject> cardList;
    private RecyclerSheetAdapter mAdapter;
    private RecyclerView recyclerView;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.sheet_chat, container, false);

        recyclerView = (RecyclerView) view.findViewById(R.id.recycler_view_chat);
        cardList = new ArrayList<>();
        mAdapter = new RecyclerSheetAdapter(this, cardList);
        LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity(),LinearLayoutManager.HORIZONTAL, false);
        recyclerView.setLayoutManager(layoutManager);
        //recyclerView.setItemAnimator(new DefaultItemAnimator());
        recyclerView.setAdapter(mAdapter);
        recyclerView.setHasFixedSize(true);

        return view;
    }
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question