【问题标题】:Android: Recycler view inside ScrollView is not workingAndroid:ScrollView 内的回收站视图不起作用
【发布时间】:2016-01-04 07:06:35
【问题描述】:

我试图将 RecyclerView 放在 ScrollView 中,我在 recycler 视图上方有布局,所以我想滚动布局和 回收器。

在我的主布局中,我有两个子布局,一个有 recyclerView,另一个有一个图像。两个布局都在 scrollView 内。当我在布局中向上滚动时,我想同时滚动

我知道我们不能在一个布局中放置两个滚动视图的问题。 我正在搜索是否有任何逻辑可以scroll layoutrecycler View

布局.xml

<?xml version="1.0" encoding="utf-8"?>
 <LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/backgorund"
android:weightSum="1">

 <ScrollView
    android:id="@+id/scrollView1"

    android:layout_width="match_parent"
    android:fillViewport="true"
android:layout_height="match_parent" >

<LinearLayout

    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:weightSum="1">
<LinearLayout
    android:id="@+id/layout_top_balance"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight=".25">

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

        <TextView
            android:id="@+id/txt_balance"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:textSize="35dp"
            android:textColor="@color/black"
            android:text="$60 USD"/>
        <TextView
            android:layout_below="@+id/txt_balance"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:textSize="20dp"
            android:textColor="#828282"
            android:text="Account Balance"/>
    </RelativeLayout>
</LinearLayout>
<LinearLayout
    android:id="@+id/layout_feeds"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:paddingLeft="16dp"
    android:paddingBottom="5dp"
    android:layout_weight=".75">

    <view
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        class="android.support.v7.widget.RecyclerView"
        android:id="@+id/recycler_view"
        android:layout_alignParentStart="true"
        android:layout_alignParentLeft="true"/>
</LinearLayout>
    </LinearLayout>
</ScrollView>

请任何人帮忙解决这个问题:)

【问题讨论】:

  • RecyclerView它自己一个ScrollView
  • 在我的主布局中,我有两个子布局,一个有recyclerView,另一个有一个图像。两个布局都在滚动视图内。当我在布局中向上滚动时,我想同时滚动 @IntelliJ Amiya
  • @BinilS 您可以将这些部分添加为 RecyclerView 的标题
  • 或者你可以自定义你附加到recyclerview的布局管理器并使用NestedScrollView

标签: android android-layout android-recyclerview android-scrollview android-scroll


【解决方案1】:

不建议在android中滚动里面滚动。回收站视图本身就是一个滚动条。似乎您想要列表“layout_top_balance”上方的可滚动部分。将此视图添加为回收器视图的标题并删除滚动视图。这将解决您的问题。

【讨论】:

    【解决方案2】:

    如果你想添加标题,你可以使用这个回收视图库

    RecyclerViewHeader Example 1

    RecyclerViewHeader Example 2

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-09-22
      • 2021-04-16
      • 2021-11-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-28
      • 2018-05-30
      相关资源
      最近更新 更多