滚动视图中的水平回收视图中的滚动问题

时间:2017-09-26 05:57:51

标签: android android-recyclerview gesture android-scrollview android-touch-event

我的主页中有一个滚动视图,在滚动视图中,每个回收视图的布局有两个布局,每个recyclerview将水平滚动。当我尝试滚动recyclerview时,scrollview的滚动被吸入,并且scrollview开始在垂直方向滚动。所以我尝试了下面的代码。

mRecyclerView.addOnItemTouchListener(new RecyclerView.OnItemTouchListener() {
    @Override
    public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) {
        int action = e.getAction();
        switch (action) {
        case MotionEvent.ACTION_MOVE:
            rv.getParent().requestDisallowInterceptTouchEvent(true);
            break;
    }
    return false;
}

@Override
public void onTouchEvent(RecyclerView rv, MotionEvent e) {

}

@Override
public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) {

    }
});

然后,当我触摸recyclerview时,我可以控制水平滚动,但现在问题是当我触摸recyclerviews时,我无法滚动我的滚动视图。任何建议请。 我的确切需要是我需要滚动视图,在滚动视图中,几个recyclerviews都在那里,它将像google play store app一样工作。

enter image description here

这是我的布局

<com.sothree.slidinguppanel.SlidingUpPanelLayout
    android:id="@+id/sliding_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    sothree:umanoPanelHeight="368dp"
    sothree:umanoParallaxOffset="2dp"
    sothree:umanoOverlay="false"
    android:gravity="bottom"
    sothree:umanoFadeColor="#00000000"
    sothree:umanoDragView="@+id/dragView"
    sothree:umanoScrollableView="@+id/svScroll"
    sothree:umanoShadowHeight="0dp">

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

    </LinearLayout>

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

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

        <ScrollView
            android:id="@+id/svScroll"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">
                <FrameLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">
                    <android.support.v4.view.ViewPager
                        android:id="@+id/vpImage"
                        android:layout_width="match_parent"
                        android:clickable="false"
                        android:layout_height="170dp" />
                    <ImageView
                        android:id="@+id/ivDefaultAd"
                        android:layout_width="match_parent"
                        android:layout_height="170dp"
                        android:scaleType="centerCrop"
                        android:src="@drawable/default_ad"/>

                </FrameLayout>
                <android.support.v7.widget.CardView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    card_view:cardBackgroundColor="@color/transparent"
                    android:layout_marginBottom="@dimen/space_1_5x"
                    android:layout_marginTop="@dimen/space_1_5x">

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

                        <LinearLayout
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:background="@color/white"
                            android:gravity="center_vertical"
                            android:orientation="horizontal"
                            >

                            <ImageView
                                android:layout_width="25dp"
                                android:layout_height="25dp"
                                android:layout_marginLeft="@dimen/space_2x"
                                android:src="@drawable/ic_image"
                                android:tint="@color/blue"/>

                            <TextView
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:layout_weight="1"
                                android:padding="@dimen/space_2x"


                                android:textSize="@dimen/txt_x_medium" />

                            <TextView

                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:gravity="center_vertical"
                                android:text="@string/more"
                                android:textColor="@color/more_orange"
                                android:textSize="@dimen/txt_medium"
                                tools:ignore="UnusedAttribute" />
                            <ImageView
                                android:layout_width="15dp"
                                android:layout_height="15dp"
                                android:tint="@color/more_orange"
                                android:layout_marginRight="@dimen/space_2x"
                                android:src="@drawable/ic_right_arrow_small"/>
                        </LinearLayout>

                        <View
                            android:layout_width="match_parent"
                            android:layout_height="1dp"
                            android:background="@color/light_gray1" />

                        <FrameLayout
                            android:layout_width="match_parent"
                            android:layout_height="150dp"
                            android:focusableInTouchMode="true"
                            android:focusable="true"
                            android:background="@color/white">
                            <com.wang.avi.AVLoadingIndicatorView
                                android:id="@+id/avi"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:layout_centerInParent="true"
                                android:layout_gravity="center"

                                app:indicatorName="LineSpinFadeLoaderIndicator" />

                            <android.support.v7.widget.RecyclerView

                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:background="@color/transparent"
                                android:orientation="horizontal" />
                            <LinearLayout

                                android:layout_width="match_parent"
                                android:layout_height="match_parent"
                                android:background="@color/white"
                                android:gravity="center"
                                android:visibility="gone">

                                <TextView
                                    android:layout_width="wrap_content"
                                    android:layout_height="wrap_content"
                                    android:text="@string/txt_msg_no_data"
                                    android:textColor="@color/no_items_txt_color"
                                    android:textSize="@dimen/txt_x_medium" />
                            </LinearLayout>
                        </FrameLayout>

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

                <android.support.v7.widget.CardView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    card_view:cardBackgroundColor="@color/transparent">

                    <LinearLayout

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

                        <LinearLayout
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:background="@color/white"
                            android:gravity="center_vertical"
                            android:orientation="horizontal"
                            android:tag="sticky">

                            <ImageView
                                android:layout_width="25dp"
                                android:layout_height="25dp"
                                android:layout_marginLeft="@dimen/space_2x"

                                android:tint="@color/blue"
                                android:contentDescription="@string/content_desc"/>

                            <TextView
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:layout_weight="1"
                                android:padding="@dimen/space_2x"
                                android:textSize="@dimen/txt_x_medium" />

                            <TextView

                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:gravity="center_vertical"
                                android:text="@string/more"
                                android:textColor="@color/more_orange"
                                android:textSize="@dimen/txt_medium"
                                tools:ignore="UnusedAttribute" />
                            <ImageView
                                android:layout_width="15dp"
                                android:layout_height="15dp"
                                android:tint="@color/more_orange"
                                android:layout_marginRight="@dimen/space_2x"
                                android:src="@drawable/ic_right_arrow_small"/>
                        </LinearLayout>

                        <View
                            android:layout_width="match_parent"
                            android:layout_height="1dp"
                            android:background="@color/light_gray1" />

                        <FrameLayout
                            android:layout_width="match_parent"
                            android:layout_height="150dp"
                            android:background="@color/white">
                            <com.wang.avi.AVLoadingIndicatorView
                                android:id="@+id/avLoader2"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:layout_centerInParent="true"
                                android:layout_gravity="center"

                                app:indicatorName="LineSpinFadeLoaderIndicator" />

                            <android.support.v7.widget.RecyclerView

                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:background="@color/transparent" />
                            <LinearLayout

                                android:layout_width="match_parent"
                                android:layout_height="match_parent"
                                android:background="@color/white"
                                android:gravity="center"
                                android:visibility="gone">

                                <CanaroTextView
                                    android:layout_width="wrap_content"
                                    android:layout_height="wrap_content"
                                    android:text="@string/txt_msg_no_data"
                                    android:textColor="@color/no_items_txt_color"
                                    android:textSize="@dimen/txt_x_medium" />
                            </LinearLayout>

                        </FrameLayout>
                    </LinearLayout>
                </android.support.v7.widget.CardView>
            </LinearLayout>
        </ScrollView>


    </LinearLayout>
</com.sothree.slidinguppanel.SlidingUpPanelLayout>

2 个答案:

答案 0 :(得分:0)

你应该使用 NestedScrollView scrollview

  

NestedScrollView与ScrollView类似,但它支持在新旧版本的Android上充当嵌套滚动父级和子级。默认情况下启用嵌套滚动。

阅读 ScrollView vs NestedScrollView

并且忘了让你的 Recycelrveiw setNestedScrollingEnabled(false);

  

<强> setNestedScrollingEnabled(boolean enabled)

     

启用或禁用此视图的嵌套滚动。

<强>码

YourRecyclerView.setNestedScrollingEnabled(false);

答案 1 :(得分:0)

您可以使用两个回收站视图(嵌套在一个父级垂直回收站视图中的水平回收站视图)。它会更有效并且可以平滑滚动。

相关问题