Android RecyclerView高度为match_parent减去固定高度

时间:2017-06-09 16:53:44

标签: android xml android-layout

我有几个需要在垂直布局中共存的RecyclerViews。顶部可以水平滚动,底部可以垂直滚动。但是,用户应该能够垂直滚动它们。为此,我遵循了question的第一个解决方案。这在一定程度上起作用,但我需要能够设置底部回收器视图的高度以匹配其父视图的高度(几乎与设备一样高)减去顶部回收器视图的高度(以及一些TextViews)。

这是布局代码:

<ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">

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

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:padding="10dp"
                android:text="Txt1"
                android:textSize="18dp"
                android:textColor="@android:color/darker_gray"
                android:textAlignment="center"/>

            <com.kwippit.android.uicomponents.EmptyRecyclerView
                android:id="@+id/horizontal_recycler_view"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"/>

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:padding="10dp"
                android:text="Txt2"
                android:textSize="18dp"
                android:textColor="@android:color/darker_gray"
                android:textAlignment="center"/>

            <android.support.v4.widget.SwipeRefreshLayout
                android:id="@+id/refresh"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <com.kwippit.android.uicomponents.EmptyRecyclerView
                    android:id="@+id/grid_recycler_view"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"/>

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

        </LinearLayout>

    </ScrollView>

我尝试将底部回收视图设置为特定高度但滚动时看起来不太正确,因为它显示的项目数量事先未知,顶部回收器视图保留在屏幕上而不是在向下滚动时隐藏

有什么想法吗?感谢。

1 个答案:

答案 0 :(得分:0)

我没有完全解决您的问题,但也许这个库可以帮助您处理Recycler Views: https://github.com/lucasr/twoway-view

我希望它有帮助:)