简体   繁体   English

NestedScrollView内的回收者视图

[英]Recycler View inside a NestedScrollView

I have a few Horizontally scrollable Recycler views inside a NestedScrollView. 我在NestedScrollView中有几个可水平滚动的Recycler视图。 How do I disable only the vertical scroll in the recycler views and pass this vertical touch to the parent NestedScrollView? 如何在回收者视图中仅禁用垂直滚动,并将此垂直触摸传递给父NestedScrollView?

try this 尝试这个

<?xml version="1.0" encoding="utf-8"?>

<android.support.design.widget.AppBarLayout
    android:id="@+id/appbar"
    android:layout_width="match_parent"
    android:layout_height="192dp"
    android:fitsSystemWindows="true"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/collapsing_toolbar"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        app:contentScrim="@color/toolbarScrim"
        app:title=" "
        app:expandedTitleTextAppearance="@android:color/transparent"
        app:layout_scrollFlags="scroll|exitUntilCollapsed">
        <com.android.volley.toolbox.NetworkImageView
            android:id="@+id/ArticleImg"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@drawable/article_img"
            android:fitsSystemWindows="true"
            android:scaleType="centerCrop"
            app:layout_collapseMode="parallax" />
        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:layout_collapseMode="pin"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
    </android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>

<android.support.v4.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ffe5e5e5"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">
    <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"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        tools:context="com.global.jet.global.BizForum.ArticleView"
        tools:showIn="@layout/activity_article_view">


        <RelativeLayout

            android:layout_marginTop="10dp"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/view2">

            <ImageView
                android:layout_margin="10dp"
                android:layout_width="64dp"
                android:layout_height="64dp"
                android:id="@+id/imageView9"
                android:background="@drawable/rv"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true"
                android:layout_marginLeft="10dp"
                android:layout_marginStart="10dp"
                />

            <TextView
                android:layout_marginLeft="10dp"
                android:textColor="@color/link"
                android:textSize="18sp"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:text="Medium Text"
                android:id="@+id/ArticlePostName"
                android:layout_alignParentTop="true"
                android:layout_toRightOf="@+id/imageView9"
                android:layout_toEndOf="@+id/imageView9" />

            <ImageView
                android:layout_marginRight="10dp"
                android:layout_width="20dp"
                android:layout_height="20dp"
                android:src="@mipmap/ic_add_black_18dp"
                android:id="@+id/button3"
                android:layout_alignParentTop="true"
                android:layout_alignParentRight="true"
                android:layout_alignParentEnd="true" />

            <TextView
                android:layout_marginLeft="10dp"
                android:textSize="14sp"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:text="31 oct 2015,12:49-"
                android:id="@+id/ArticleDate"
                android:layout_below="@+id/ArticlePostName"
                android:layout_toRightOf="@+id/imageView9"
                android:layout_toEndOf="@+id/imageView9" />

            <TextView
                android:layout_marginLeft="10dp"
                android:textColor="@color/link"
                android:textSize="14sp"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:text="Medium Text"
                android:id="@+id/ArticleDes"
                android:layout_below="@+id/ArticleDate"
                android:layout_toRightOf="@+id/imageView9"
                android:layout_toEndOf="@+id/imageView9" />

            <ImageView
                android:background="@drawable/clock_ic"
                android:textSize="14sp"
                android:layout_width="18dp"
                android:layout_height="18dp"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:text="Small Text"
                android:id="@+id/textView15"
                android:layout_alignTop="@+id/ArticleDate"
                android:layout_toRightOf="@+id/ArticleDate"
                android:layout_toEndOf="@+id/ArticleDate" />

            <TextView
                android:layout_marginLeft="5dp"
                android:textSize="14sp"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:text="3 min read"
                android:id="@+id/ArticleTime"
                android:layout_alignTop="@+id/textView15"
                android:layout_toRightOf="@+id/textView15"
                android:layout_toEndOf="@+id/textView15" />

            <View
                android:layout_marginTop="10dp"
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:background="@color/grey_333"
                android:id="@+id/textView17"
                android:layout_below="@+id/imageView9"
                android:layout_alignLeft="@+id/imageView9"
                android:layout_alignStart="@+id/imageView9"
                android:layout_alignRight="@+id/button3"
                android:layout_alignEnd="@+id/button3" />             
        </RelativeLayout>
    </RelativeLayout>

</android.support.v4.widget.NestedScrollView>
<android.support.v7.widget.RecyclerView
     android:id="@+id/scrollableview"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     app:layout_behavior="@string/appbar_scrolling_view_behavior" />

I'd say you set an touch listener for the RecyclerView and detect whether it is horizontal or vertical scroll. 我想说您为RecyclerView设置了一个触摸侦听器,并检测它是水平滚动还是垂直滚动。 Return true when it is horizontal and return false when it is vertical. 返回true当它是水平的,并返回false时,它是垂直的。

RecyclerView rv = findViewById(R.id.recyclerView);
rv.setOnTouchListener(new View.OnTouchListener {
    public boolean onTouch(View v, MotionEvent event) {
        // your logic here
    }
});

Reference - View.OnTouchListener 参考-View.OnTouchListener

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 具有CoordinatorLayout的NestedScrollView内的回收者视图 - Recycler view Inside NestedScrollView with CoordinatorLayout Recycler视图内的NestedScrollview不滚动 - NestedScrollview inside a Recycler view not scrolling 带ImageView和Recycler视图的NestedScrollView - NestedScrollView with ImageView and Recycler view 当回收器视图放在nestedscrollview中时,PagedListAdapter获取所有项目 - PagedListAdapter fetching all the items when recycler view is placed inside nestedscrollview NestedScrollView 中的 Recycler 视图导致滚动从中间开始 - Recycler view inside NestedScrollView causes scroll to start in the middle 在 NestedScrollView 中,Recycler View 加载大数据时非常慢 - Recycler View loading very slow for large data when inside NestedScrollView 在nestedscrollview中滚动多个水平回收器视图,它们之间带有视图分隔符 - scroll multiple horizonal recycler-view with view-separator between them inside nestedscrollview Recycler 视图中的 Recycler 视图 - Recycler view inside Recycler view NestedScrollView 修复 NestedScrollView 内的视图顶部 - NestedScrollView fix the view top inside NestedScrollView 回收站视图中的弹出窗口 - Popup inside a recycler View
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM