【问题标题】:Access other view with recycler view android studio使用回收站视图 android studio 访问其他视图
【发布时间】:2017-10-04 15:03:55
【问题描述】:

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

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

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

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

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

【问题讨论】:

  • 您需要在 RecyclerView 中添加第一个和第二个布局作为项目,并使用不同的视图类型

标签: java android android-layout android-recyclerview


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    如果您的两个 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,您可以使用权重(顶部 LinearLayout 为 1,底部 LinearLayout 为 1,RecyclerView 为 3)

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-10-21
      • 1970-01-01
      • 2017-03-19
      • 2019-04-18
      • 2017-08-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多