【问题标题】:Recyclerview within a Scrollview dont coordinateScrollview 中的 Recyclerview 不坐标
【发布时间】:2017-07-08 01:01:02
【问题描述】:

我有这个活动设计,它在scrollView 中显示了一个卡片视图,但在cardview 下我需要放置一个listviewrecyclerview。问题是我需要该列表的滚动与主滚动协调。 Osea,当内容较低时,cardview 将消失,recyclerview 或列表视图的列表将被交叉。

我需要所有响应主滚动的内容在titlebar之后显示和消失,我应该更改或重新设计哪个?

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


    <android.support.v7.widget.CardView
        app:cardElevation="5dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <android.support.design.widget.CoordinatorLayout
            android:id="@+id/post_coordinator"
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <ImageView
                android:id="@+id/post_bg"
                android:layout_width="match_parent"
                android:layout_height="150dp"
                android:scaleType="fitXY"
                android:src="@drawable/default_profile" />

            <android.support.design.widget.FloatingActionButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                app:fabSize="normal"
                android:src="@drawable/ic_hot_black"
                app:layout_anchorGravity="bottom"
                android:layout_marginLeft="16dp"
                app:layout_anchor="@id/post_bg"
                android:tint="#FFF"
                />

            <com.mikhaellopez.circularimageview.CircularImageView
                android:layout_width="100dp"
                android:layout_height="100dp"
                app:layout_anchor="@id/post_bg"
                app:layout_anchorGravity="center_horizontal|bottom"
                android:src="@drawable/profile"
                app:civ_border_color="#FFF"
                app:civ_border_width="3dp"
                />


            <android.support.design.widget.FloatingActionButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                app:fabSize="normal"
                android:src="@drawable/ic_hot_black"
                app:layout_anchorGravity="bottom|end"
                android:layout_marginRight="16dp"
                app:layout_anchor="@id/post_bg"
                android:tint="#FFF"
                />


            <LinearLayout
                android:orientation="vertical"
                android:layout_width="match_parent"
                android:layout_marginTop="205dp"
                android:paddingLeft="20dp"
                android:paddingRight="20dp"
                android:paddingBottom="50dp"
                android:layout_height="wrap_content">


                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="Prepare your Anus Cersei Lanister, You Gonna Die"
                    android:textAppearance="@style/Base.TextAppearance.AppCompat.Large"
                    android:textColor="#2d2d2d"
                    android:textAlignment="center"
                    />


                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:textAlignment="center"
                    android:text="@string/emilia"
                    android:textColor="@color/secondary_text"
                    android:layout_marginTop="10dp"
                    />

            </LinearLayout>

        </android.support.design.widget.CoordinatorLayout>

    </android.support.v7.widget.CardView>


    <ListView
        android:id="@+id/post_comments"
        android:layout_marginTop="16dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        >
    </ListView>

    </LinearLayout>
</ScrollView>

【问题讨论】:

  • 您不应该将一个滚动视图放在另一个滚动视图中。即:ListViewScrollView 内。如果必须使用NestedScrollViewRecyclerView

标签: android listview android-recyclerview scrollview


【解决方案1】:

在 NestedScrollview 中添加您的回收站视图。 还要添加recyclerview.setNestedScrollingEnabled(false);

【讨论】:

    【解决方案2】:

    对 ScrollView 使用 android:fillViewport="true"。位于 ScrollView 内的 ListView 工作正常。

    <ScrollView
    android:id="@+id/scrollView" 
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true">
    

    【讨论】:

      【解决方案3】:

      我建议将CardView 放在RecyclerView 中作为标题,然后您不需要顶部的ScrollView,卡片和列表项都将是可在RecyclerView 内滚动。

      有很多方法可以向RecyclerView 添加标头,请参见此处: Is there an addHeaderView equivalent for RecyclerView?

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-10-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-01-13
        相关资源
        最近更新 更多