代码之家  ›  专栏  ›  技术社区  ›  Parth Anjaria

ScrollView中的RecyclerView

  •  0
  • Parth Anjaria  · 技术社区  · 6 年前

    这是代码:

        <?xml version="1.0" encoding="utf-8"?>
    <ScrollView 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/grey_f2"
        android:fillViewport="true"
        >
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        >
        <android.support.v7.widget.RecyclerView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/rv_achievement_badges"
            android:focusableInTouchMode="false"
    
            />
        <LinearLayout
            android:background="@color/white"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:padding="25dp"
            >
            <com.sharesmile.share.views.LBTextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/hall_of_fame"
                android:layout_marginTop="10dp"
                android:layout_marginBottom="10dp"
                android:textColor="@color/black_64"
                android:textSize="20sp"
                />
            <android.support.v7.widget.RecyclerView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/rv_hall_of_fame"
                android:focusableInTouchMode="false"
                />
        </LinearLayout>
    </LinearLayout>
    </ScrollView>
    

    问题是 rv_hall_of_fame 不显示所有项目。 已尝试NestedsRollView、Viewport、CanScrollVertical和SetNestedScrollingEnabled,但没有任何工作。你能告诉我吗?

    2 回复  |  直到 6 年前
        1
  •  1
  •   Rohit45    6 年前

    您应该从线性布局中删除第二个RecyclerView。也许这就是你看不到所有物品的原因。

    编辑:

    我认为您应该使用NestedScrollView。我在一个项目中也遇到了同样的问题,我将代码改为下面的代码,解决了我的问题。

    <?xml version="1.0" encoding="utf-8"?>
    <android.support.v4.widget.NestedScrollView 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/grey_f2"
    android:fillViewport="true"
    android:focusableInTouchMode="true">
    
    <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">
    
    <android.support.v7.widget.RecyclerView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/rv_achievement_badges"/>
    
    <com.sharesmile.share.views.LBTextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="@string/hall_of_fame"
    android:layout_marginTop="10dp"
    android:textColor="@color/black_64"
    android:textSize="20sp"
    android:background="@color/white"
    android:paddingLeft="25dp"
    android:paddingTop="36dp"/>
    
    <android.support.v7.widget.RecyclerView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/rv_hall_of_fame"
    android:background="@color/white"
    android:layout_marginBottom="7dp"
    android:paddingBottom="30dp"
    android:paddingTop="30dp"
    android:paddingLeft="25dp"
    android:paddingRight="25dp"/>
    
    </LinearLayout>
    
    </android.support.v4.widget.NestedScrollView>
    
        2
  •  0
  •   Roc Boronat    6 年前

    把一个 RecyclerView 或A ListView A内 ScrollView . Android不知道如何处理用户事件。另外,在你的例子中,你有两个 回收视图 在树根里 卷轴视图 …Android用户界面框架和用户都很疯狂。

    解决方案可以是只使用一个 回收视图 它处理滚动用户操作,以及 Adapter 这就知道如何渲染你所使用的一切:成就徽章、名人堂标签和玩家。所以,你只需要一个 回收视图 它会像一个魅力。