使用recycler查看android studio访问其他视图

时间:2017-10-04 15:03:56

标签: java android android-layout android-recyclerview

如下图所示。我在回收者视图上方有一个布局,下面有一个布局。两个标签都是线性布局。我面临两个问题。

  1. 因为回收者视图具有内部滚动,因此如果回收器视图中的项目增加,则第一个线性布局保持在同一位置,但我希望它在滚动项目时向上滚动。

  2. 当回收者视图中的项目增加时,第二个布局消失。如何在回收者视图到达其最后一个项目时滚动布局。

  3. 尝试了android:nestedScrollingEnabled =" false"它会禁用滚动效果,但在回收器视图中只显示几个项目。

    需要解决方案:如果以某种方式我可以使回收者查看项目静态并显示所有可用内容。所以父布局决定是否滚动。如果尺寸增加,它将滚动,否则不会。

    enter image description here

2 个答案:

答案 0 :(得分:0)

您可以将两个LinearLayouts作为页眉和页脚视图添加到RecyclerView。这个问题的最佳答案应该让您知道如何做到这一点:RecyclerView header and footer

答案 1 :(得分:0)

如果您的两个LinearLayout具有固定大小,您可以将它们固定在RelativeLayout中,然后在"之间插入您的RecyclerView"。

<RelativeLayout>
  <LinearLayout alignParentTop="true" height="100dp" id="@+id/topLayout"/>
  <LinearLayout alignParentBottom="true" height="100dp" id="@+id/bottomLayout"/>
  <RecyclerView height="match_parent" above="@id/bottomLayout" below="@id/topLayout"/>
</RelativeLayout>

或者,如果您的顶部容器是LinearLayout,您可以使用权重(1表示顶部LinearLayout,1表示底部LinearLayout,3表示RecyclerView)

<LinearLayout orientation="vertical">
  <LinearLayout height="0dp" weight="1"/>
  <RecyclerView height="0dp" weight="3"/>
  <LinearLayout height="0dp" weight="1"/>
</LinearLayout>