查看RecyclerView上方和下方的视图

chR*_*NaN 17 android android-recyclerview android-design-library

我有一个显示动态内容的RecyclerView.我想在其他视图之间显示这个RecyclerView.例如,上面显示的一个View和RecyclerView下面显示的一个View:

View
RecyclerView
View
Run Code Online (Sandbox Code Playgroud)

然而,无论我尝试什么似乎都没有工作,RecyclerView似乎占据了整个空间.我相信问题在于wrap_content问题,虽然我已经尝试了一些建议的解决方案,例如这个自定义LinearLayoutManager,但它似乎没有解决我的问题.

尝试:

<?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:fitsSystemWindows="true">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <!-- AppBar works fine; no issue here -->
        <android.support.design.widget.AppBarLayout
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:id="@+id/app_bar_layout">

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_height="?attr/actionBarSize"
                android:layout_width="match_parent"
                app:layout_collapseMode="pin"/>

        </android.support.design.widget.AppBarLayout>

        <!-- Not displaying; Tried different views -->
        <com.chrynan.taginput.view.TextInputWrapper
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/edit_text_container">
            <AutoCompleteTextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/edit_text"/>
        </com.chrynan.taginput.view.TextInputWrapper>

        <!-- Takes up entire screen space -->
        <android.support.v4.widget.SwipeRefreshLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/swipe_refresh">

            <android.support.v7.widget.RecyclerView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/recycler_view"/>

        </android.support.v4.widget.SwipeRefreshLayout>

        <!-- Not displaying -->
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/text_view"/>

    </LinearLayout>

</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)

问题:有没有办法在RecyclerView上方放置和显示上方视图和视图?如果是这样,怎么样?或者使用ListView更好?

sau*_*lmm 32

用法怎么样weight?

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://..."
    android:layout_width="match_parent"
    android:layout_height="match_parent"        
    android:orientation="vertical"
    >

    <View
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        />

    <RecyclerView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        />

    <View
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)