代码之家  ›  专栏  ›  技术社区  ›  Samuel

将RecyclerView嵌套在另一个布局中会隐藏列表

  •  0
  • Samuel  · 技术社区  · 7 年前

    由Android Studio自动生成:

    浏览\u recycler \u 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"/>
    

        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 回复  |  直到 7 年前
        1
  •  1
  •   PushpikaWan    7 年前

    把你的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>