Вложение RecyclerView внутри другого макета скрывает список - PullRequest
0 голосов
/ 28 октября 2018

В Android Studio 3.2.1 я создал Файл-> Создать-> Фрагмент-> Фрагмент (Список), и он автоматически создал список RecyclerView, который работает, но если я пытаюсь вложить RecyclerView в другой макет, он скрывает список.Я перепробовал все, чтобы это сработало, но не могу этого сделать.Я просто хочу создать панель действий под списком внизу экрана.

Как автоматически генерируется Android Studio:

browse_recycler_view.xml:

<android.support.v7.widget.RecyclerView
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/list"
        android:name="com.hssw.hssw_petmatch.FragmentBrowse"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="16dp"
        android:layout_marginRight="16dp"
        app:layoutManager="android.support.v7.widget.LinearLayoutManager"
        tools:context=".FragmentBrowse"
        tools:listitem="@layout/fragment_browse_item"/>

FragmentBrowse.java:

    public void onCreate(Bundle savedInstanceState)
        {
        super.onCreate(savedInstanceState);
        if(getArguments() != null)
            {
            mColumnCount = getArguments().getInt(ARG_COLUMN_COUNT);
            }
        }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
        View view = inflater.inflate(R.layout.browse_recycler_view, container, false);
        // Set the adapter
        if(view instanceof RecyclerView)
            {
            Context context = view.getContext();
            RecyclerView recyclerView = (RecyclerView) view;
            if(mColumnCount <= 1)
                {
                recyclerView.setLayoutManager(new LinearLayoutManager(context));
                }
            else
                {
                recyclerView.setLayoutManager(new GridLayoutManager(context, mColumnCount));
                }
            recyclerView.setAdapter(new BrowseRecyclerViewAdapter(DummyContent.ITEMS, mListener));
            }
        return view;
        }

1 Ответ

0 голосов
/ 28 октября 2018

Поместите свой RecyclerView в макет Координатора.как ниже

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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.support.v7.widget.RecyclerView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/list"
    android:name="com.hssw.hssw_petmatch.FragmentBrowse"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="16dp"
    android:layout_marginRight="16dp"
    app:layoutManager="android.support.v7.widget.LinearLayoutManager"
    tools:context=".FragmentBrowse"
    tools:listitem="@layout/fragment_browse_item"/>

</android.support.design.widget.CoordinatorLayout>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...