【问题标题】:RecyclerView not working within NestedScrollviewRecyclerView 在 NestedScrollview 中不起作用
【发布时间】:2019-03-22 17:17:14
【问题描述】:

过去曾多次问过 RecyclerView 的类似问题,我也尝试过我的代码的解决方案,但我仍然无法为我的问题找到实际的解决方案。 顺便说一句,如果这对这个问题很重要,我正在使用 UltimateRecyclerView 库。

这是我的 xml 代码,

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".activities.TestChartActivity">

    <android.support.v4.widget.NestedScrollView
        android:id="@+id/main_scroll_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true">

        <RelativeLayout
            android:id="@+id/main_layout_transactions"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <info.hoang8f.android.segmented.SegmentedGroup xmlns:segmentedgroup="http://schemas.android.com/apk/res-auto"
                android:id="@+id/rdGrpChartType"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="8dp"
                android:orientation="horizontal"
                android:weightSum="4"
                segmentedgroup:sc_border_width="2dp"
                segmentedgroup:sc_corner_radius="5dp">

                <RadioButton
                    android:id="@+id/rdBtn1m"
                    style="@style/RadioButton"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:layout_weight="1"
                    android:button="@null"
                    android:gravity="center"
                    android:padding="2dp"
                    android:text="1M" />

                <RadioButton
                    android:id="@+id/rdBtn3m"
                    style="@style/RadioButton"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:layout_weight="1"
                    android:button="@null"
                    android:gravity="center"
                    android:padding="2dp"
                    android:text="3M" />

                <RadioButton
                    android:id="@+id/rdBtn6m"
                    style="@style/RadioButton"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:layout_weight="1"
                    android:button="@null"
                    android:gravity="center"
                    android:padding="2dp"
                    android:text="6M" />

                <RadioButton
                    android:id="@+id/rdBtn12m"
                    style="@style/RadioButton"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:layout_weight="1"
                    android:button="@null"
                    android:gravity="center"
                    android:padding="2dp"
                    android:text="12M" />

            </info.hoang8f.android.segmented.SegmentedGroup>


            <Spinner
                android:id="@+id/spinner_property"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/rdGrpChartType"
                android:layout_margin="5dp" />


            <com.github.mikephil.charting.charts.CombinedChart
                android:id="@+id/reports"
                android:layout_width="match_parent"
                android:layout_height="300dp"
                android:layout_below="@+id/layout_transaction_summary"
                android:layout_marginBottom="20dp"
                android:layout_marginEnd="10dp"
                android:layout_marginStart="10dp" />

            <RelativeLayout
                android:id="@+id/layout_transactions_list"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_below="@+id/reports">

                <LinearLayout
                    android:id="@+id/transactions_buttons_layout"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginBottom="@dimen/regular_margin"
                    android:layout_marginEnd="@dimen/fab_margin_right"
                    android:layout_marginStart="@dimen/fab_margin_right"
                    android:layout_marginTop="10dp"
                    android:elevation="2dp"
                    android:orientation="horizontal">

                    <RadioGroup
                        android:id="@+id/transactions_switch_layout"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:background="@drawable/transactions_switch_background_border"
                        android:orientation="horizontal">

                        <RadioButton
                            android:id="@+id/radio_transaction_income"
                            android:layout_width="0dp"
                            android:layout_height="match_parent"
                            android:layout_weight="1"
                            android:background="@drawable/income_switch_background_selector"
                            android:button="@null"
                            android:checked="true"
                            android:fontFamily="sans-serif-medium"
                            android:gravity="center"
                            android:paddingBottom="8dp"
                            android:paddingTop="8dp"
                            android:text="@string/title_income"
                            android:textAllCaps="true"
                            android:textColor="@color/income_switch_color_selector" />

                        <RadioButton
                            android:id="@+id/radio_transaction_expense"
                            android:layout_width="0dp"
                            android:layout_height="match_parent"
                            android:layout_weight="1"
                            android:background="@drawable/expense_switch_background_selector"
                            android:button="@null"
                            android:fontFamily="sans-serif-medium"
                            android:gravity="center"
                            android:paddingBottom="8dp"
                            android:paddingTop="8dp"
                            android:text="@string/title_expense"
                            android:textAllCaps="true"
                            android:textColor="@color/expense_switch_color_selector" />


                    </RadioGroup>
                </LinearLayout>


                <com.marshalchen.ultimaterecyclerview.UltimateRecyclerView
                    android:id="@+id/income_recycler_view"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_below="@+id/transactions_buttons_layout"
                    android:visibility="visible"
                    app:recyclerviewClipToPadding="true"
                    app:recyclerviewPadding="2dp" />

                <com.marshalchen.ultimaterecyclerview.UltimateRecyclerView
                    android:id="@+id/expense_recycler_view"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_below="@+id/transactions_buttons_layout"
                    android:visibility="gone"
                    app:recyclerviewClipToPadding="true"
                    app:recyclerviewPadding="2dp" />

            </RelativeLayout>

            <LinearLayout
                android:id="@+id/no_transaction"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:gravity="center"
                android:orientation="vertical"
                android:visibility="gone">

                <ImageView
                    android:id="@+id/no_transaction_img"
                    android:layout_width="60dp"
                    android:layout_height="60dp"
                    app:srcCompat="@drawable/ic_no_transaction" />

                <TextView
                    android:id="@+id/txt_no_transaction"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="5dp"
                    android:text="@string/str_no_transaction"
                    android:textColor="@color/darkestGrey"
                    android:textSize="20sp" />

            </LinearLayout>
        </RelativeLayout>
    </android.support.v4.widget.NestedScrollView>
</RelativeLayout>

我附上了到目前为止我使用上述代码实现的图像,其中 RecyclerView 本身保持固定且可滚动,但我无法滚动整个列表布局。

任何帮助将不胜感激。

【问题讨论】:

    标签: android android-layout android-recyclerview android-xml android-nestedscrollview


    【解决方案1】:

    NestedScrollView 和 RecyclerView 都有一个相同的属性,即滚动。

    如果我们在 NestedScrollView 中添加 RecyclerView ,那么有时 RecyclerView 不会滚动,或者如果滚动它会滚动,那么它会单独滚动而不是用 nestedscrollview 滚动,

    如果我们需要滚动整个布局和 recyclerview,然后在您的活动中添加以下代码:

    recyclerviewName.setNestedScrollingEnabled(false);
    

    使用上面的代码recyclerview和scroll一起。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-18
      • 1970-01-01
      • 2017-02-05
      • 1970-01-01
      • 2018-04-08
      相关资源
      最近更新 更多