带有recyclerview的scrollview中的scrollview不滚动

时间:2018-06-26 12:12:07

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

我使用了一个父滚动视图,在其中我使用了带有两个recyclerviews的子滚动视图。我已经使用了很多解决方案来将滚动应用于子scrollview,但无法做到这一点。

主要布局在下面给出

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/bid_root_rl"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/background_color">

    <include
        android:id="@+id/appbar"
        layout="@layout/toolbar" />

    <TextView
        android:id="@+id/txt_msg"
        style="@style/error_textview_style"
        android:layout_below="@+id/appbar" />

    <ScrollView
        android:id="@+id/scrollView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/llLast"
        android:layout_below="@+id/txt_msg"
        android:fillViewport="true"
        android:fitsSystemWindows="true"
        android:scrollbarThumbVertical="@drawable/scrollbar_thumb_color">

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

            <LinearLayout
                android:id="@+id/ll1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:weightSum="1">

                <RelativeLayout
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_vertical"
                    android:layout_weight="0.5"
                    android:background="@color/color_wallet_background"
                    android:padding="@dimen/dimen_10dp">

                    <TextView
                        android:id="@+id/tvBTCWalletBalance"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_centerVertical="true"
                        android:layout_marginLeft="@dimen/dimen_2dp"
                        android:layout_marginStart="@dimen/dimen_2dp"
                        android:layout_toEndOf="@id/ic_deposit"
                        android:layout_toRightOf="@id/ic_deposit"
                        android:text="09999"
                        android:textColor="@color/white"
                        android:textSize="@dimen/textSizeInvoiceBuy"
                        android:textStyle="bold" />


                    <com.ebitcoinics.ebitcoinicsapp.customview_virtual_currency.CustomVirtualCurrencyImageViewWhiteColor
                        android:id="@+id/localImageView"
                        android:layout_width="@dimen/imageSizeTooSmallBTCLogoForMin"
                        android:layout_height="@dimen/imageSizeTooSmallBTCLogoForMin"
                        android:layout_centerVertical="true"
                        android:layout_marginLeft="@dimen/dimen_2dp"
                        android:layout_marginStart="@dimen/dimen_2dp"
                        android:layout_toEndOf="@id/tvBTCWalletBalance"
                        android:layout_toRightOf="@id/tvBTCWalletBalance" />

                    <ImageView
                        android:id="@+id/ic_deposit"
                        android:layout_width="@dimen/imageSizeTooSmallBTCLogoForMin"
                        android:layout_height="@dimen/imageSizeTooSmallBTCLogoForMin"
                        android:layout_alignParentLeft="true"
                        android:layout_alignParentStart="true"
                        android:layout_centerVertical="true"
                        android:layout_marginLeft="@dimen/dimen_2dp"
                        android:layout_marginStart="@dimen/dimen_2dp"
                        android:src="@drawable/ic_deposit" />

                    <LinearLayout
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_centerVertical="true"
                        android:layout_marginLeft="@dimen/dimen_2dp"
                        android:layout_marginStart="@dimen/dimen_2dp"
                        android:layout_toEndOf="@+id/localImageView"
                        android:layout_toRightOf="@+id/localImageView"
                        android:orientation="horizontal">

                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_gravity="center_vertical"
                            android:text="("
                            android:textColor="@color/white"
                            android:textSize="@dimen/bid_ask_current_trades_size"
                            android:textStyle="bold" />

                        <TextView
                            android:id="@+id/tvPriceAsPerBuy"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_gravity="center_vertical"
                            android:layout_marginLeft="@dimen/dimen_2dp"
                            android:layout_marginStart="@dimen/dimen_2dp"
                            android:textColor="@color/white"
                            android:textSize="@dimen/bid_ask_current_trades_size"
                            android:textStyle="bold" />

                        <com.ebitcoinics.ebitcoinicsapp.customview_local_currency.CustomLocalCurrencyImageViewWhiteColor
                            android:id="@+id/imgLocalCurrencyAsPerWallet"
                            android:layout_width="@dimen/imageSizeTooSmallBTCLogoForMin"
                            android:layout_height="@dimen/imageSizeTooSmallBTCLogoForMin"
                            android:layout_gravity="center_vertical"
                            android:layout_marginLeft="@dimen/dimen_2dp"
                            android:layout_marginStart="@dimen/dimen_2dp" />

                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_gravity="center_vertical"
                            android:layout_marginLeft="@dimen/dimen_2dp"
                            android:layout_marginStart="@dimen/dimen_2dp"
                            android:text=")"
                            android:textColor="@color/white"
                            android:textSize="@dimen/bid_ask_current_trades_size"
                            android:textStyle="bold" />
                    </LinearLayout>

                </RelativeLayout>

                <View
                    android:layout_width="@dimen/dimen_1dp"
                    android:layout_height="match_parent"
                    android:background="@color/white" />

                <LinearLayout
                    android:id="@+id/txt_buy_info_ll2"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_vertical"
                    android:layout_weight="0.5"
                    android:background="@color/color_wallet_background"
                    android:padding="@dimen/dimen_10dp">

                    <include
                        android:id="@+id/ll_buy_info"
                        layout="@layout/include_layout_buy_new" />
                </LinearLayout>


            </LinearLayout>


            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/ll1"
                android:layout_margin="@dimen/dimen_10dp"
                android:orientation="vertical">

                <LinearLayout
                    android:id="@+id/ll2"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">

                    <include
                        android:id="@+id/llTop"
                        layout="@layout/common_edittext_header_for_bid_ask_new" />
                </LinearLayout>

                <include
                    android:id="@+id/activity_market_rates"
                    layout="@layout/activity_market_rates_inner_layout_ask"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content" />
            </LinearLayout>


        </RelativeLayout>

    </ScrollView>

    <LinearLayout
        android:id="@+id/llLast"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:orientation="vertical">

        <TextView
            android:id="@+id/txt1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="@string/ask_rules"
            android:textColor="@color/white"
            android:textSize="@dimen/textSizeTooMin" />

        <TextView
            android:id="@+id/txtMsgBidAsk"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="@dimen/dimen_5dp"
            android:gravity="center"
            android:text="@string/BidAskMsg"
            android:textColor="@color/white"
            android:textSize="@dimen/textSizeTooMin"
            android:textStyle="italic" />

        <android.support.v7.widget.AppCompatButton
            android:id="@+id/btn_ask"
            style="@style/button_style"
            android:layout_marginBottom="@dimen/dimen_10dp"
            android:layout_marginLeft="@dimen/dimen_10dp"
            android:layout_marginRight="@dimen/dimen_10dp"
            android:text="@string/ask" />
    </LinearLayout>
</RelativeLayout>

activity_market_rates_inner_layout_ask.xml在下面给出

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">


<LinearLayout
    android:id="@+id/rlTitle"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="@dimen/dimen_3dp"
    android:orientation="horizontal"
    android:weightSum="1">

    <ProgressBar
        android:id="@+id/progressBar"
        style="@style/Widget.AppCompat.ProgressBar.Horizontal"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="0.1"
        android:background="@drawable/progress_drawable"
        android:indeterminate="false"
        android:max="100"
        android:visibility="invisible" />

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="0.9"
        android:orientation="horizontal">

        <TextView
            android:id="@+id/txtLocal"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center_horizontal"
            android:text="@string/localPrice"
            android:textColor="@color/white"
            android:textSize="@dimen/bid_ask_current_trades_size" />

        <TextView
            android:id="@+id/txtVirtual"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center_horizontal"
            android:text="@string/localPrice"
            android:textColor="@color/white"
            android:textSize="@dimen/bid_ask_current_trades_size" />

        <TextView
            android:id="@+id/txtRate"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center_horizontal"
            android:text="@string/ratePrice"
            android:textColor="@color/white"
            android:textSize="@dimen/bid_ask_current_trades_size" />
    </LinearLayout>
</LinearLayout>

<RelativeLayout
    android:id="@+id/rlProgress"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/rlTitle"
    android:layout_gravity="center"
    android:visibility="gone">

    <ProgressBar
        android:id="@+id/progressBar2"

        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:background="@drawable/progress_color"
        android:indeterminate="true" />
</RelativeLayout>

<ScrollView
    android:id="@+id/scrollViewChild"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/rlTitle"
    android:fillViewport="true"
    android:fitsSystemWindows="true"
    android:scrollbarThumbVertical="@drawable/scrollbar_thumb_color">

    <LinearLayout
        android:id="@+id/llRV"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <android.support.v7.widget.RecyclerView
            android:id="@+id/rvSell"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />


        <android.support.v7.widget.RecyclerView
            android:id="@+id/rvBuy"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="@dimen/dimen_5dp" />
    </LinearLayout>
</ScrollView>

在这里我要滚动scrollViewChild,我曾经用过

rvSell.setNestedScrollingEnabled(false);
 rvBuy.setNestedScrollingEnabled(false);

但是只有父滚动视图滚动而不是子滚动。

2 个答案:

答案 0 :(得分:0)

尝试一下:

 recycler.setLayoutManager(new LinearLayoutManager(linear_.getContext(),
            LinearLayoutManager.VERTICAL, false){
        @Override
        public boolean canScrollHorizontally() {
            return false;
        }

        @Override
        public boolean canScrollVertically() {
            return false;
        }
    });

,而不是ScrollView,请使用NestedScrollView

答案 1 :(得分:0)

在内部xml中,尝试:

<android.support.v7.widget.RecyclerView
            android:id="@+id/rvSell"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" 
            android:overScrollMode="never"/>


<android.support.v7.widget.RecyclerView
            android:id="@+id/rvBuy"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="@dimen/dimen_5dp" 
            android:nestedScrollingEnabled="false"/>