Android 如何使水平循环视图内的水平滚动视图工作?

Android 如何使水平循环视图内的水平滚动视图工作?,android,android-studio,android-recyclerview,horizontal-scrolling,nestedrecyclerview,Android,Android Studio,Android Recyclerview,Horizontal Scrolling,Nestedrecyclerview,我搜索过类似的问题,尝试过几个答案,但没有解决。。 我有水平回收视图,显示城市名称和一些数据 问题是,我将画布条形图或RV图表(如下图所示)放置在主回收器视图适配器内的每个位置,为了水平滚动此图表,我将图表放置在水平滚动视图中,以便在从右向左滚动此图表时查看长水平方向的图表数据,反之亦然,但实际上它不会滚动仅水平主回收器视图在触摸时水平滚动以显示城市,对于RV内的此图表,触摸时未滚动以滚动(冻结) “回收器”视图是否仅在水平方向上滚动,并防止在其子视图中出现任何其他滚动 这是我的回收器视图项目

我搜索过类似的问题,尝试过几个答案,但没有解决。。 我有水平回收视图,显示城市名称和一些数据 问题是,我将画布条形图或RV图表(如下图所示)放置在主回收器视图适配器内的每个位置,为了水平滚动此图表,我将图表放置在水平滚动视图中,以便在从右向左滚动此图表时查看长水平方向的图表数据,反之亦然,但实际上它不会滚动仅水平主回收器视图在触摸时水平滚动以显示城市,对于RV内的此图表,触摸时未滚动以滚动(冻结) “回收器”视图是否仅在水平方向上滚动,并防止在其子视图中出现任何其他滚动

这是我的回收器视图项目布局

<?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"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<androidx.core.widget.NestedScrollView
    android:id="@+id/scv"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true"
    android:scrollbars="none">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"

        android:padding="10dp">
    <androidx.cardview.widget.CardView
        android:id="@+id/main_cardView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:cardCornerRadius="12dp"
        app:cardBackgroundColor="@android:color/transparent">


        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:id="@+id/linearLayoutWeather"
            android:layout_centerVertical="true"
            android:layout_centerHorizontal="true"
            android:padding="10dp">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/txtCityName2"
                android:textColor="@color/text_light"
                android:textSize="42sp"
                android:textStyle="bold"
                android:layout_gravity="center_horizontal"
                android:gravity="center_horizontal"/>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:layout_gravity="center_horizontal"
                android:gravity="center_horizontal"
                android:paddingTop="10dp">

                <ImageView
                    android:layout_width="120dp"
                    android:layout_height="120dp"
                    android:id="@+id/imgWeather2"
                    android:src="@mipmap/ic_launcher"/>

                <TextView
                    android:paddingLeft="10dp"
                    android:id="@+id/txtCityTemperature2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="30 C"
                    android:textColor="@color/text_light"
                    android:textSize="24sp"
                    android:textStyle="bold"
                    android:paddingTop="45dp"/>

            </LinearLayout>

            
        </LinearLayout>
    </androidx.cardview.widget.CardView>


        <RelativeLayout

            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center">

            <HorizontalScrollView             // here is the problem (doesn't scroll)

                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentStart="true"
                android:layout_alignParentEnd="true"
                android:layout_marginStart="0dp"
                android:layout_marginEnd="0dp"
                android:scrollbars="horizontal">


                <WeatherChartViewBars2
                    android:id="@+id/bars"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:isScrollContainer="true"

                    />
            </HorizontalScrollView>

        </RelativeLayout>


    </LinearLayout>
</androidx.core.widget.NestedScrollView>
 </RelativeLayout>

在水平滚动视图内,将天气图视图条以水平线布局。它会工作。

@Brendon让我走上正确的道路,因为我必须停止在水平循环视图中滚动,同时触摸水平滚动视图项目,如条形图。键是水平滚动视图的getparent。我还为adapter view holder中希望水平滚动的每个项目执行了此操作

    holder.horizontalScrollView.setOnTouchListener(new 
        View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            
     holder.horizontalScrollView.getParent().
      requestDisallowInterceptTouchEvent(true);


            return false;
        }
    });

非常感谢。它在模拟器上不工作,但我在实际的设备上试过,它工作得非常慢,并且冻结了水平移动的条形图。我的意思是条形图冻结和城市回收器视图水平滚动,因此,当尝试水平滚动时,结果条形图滚动非常慢或冻结,如果我使RV垂直,它可以很好地水平滚动条。那么您的问题解决了吗?还没有,我认为使回收器视图线性布局管理器水平,以防止任何水平在它里面滚动,即使我把这个条形图放在水平滚动视图中,主RV只在水平方向滚动,冻结滚动里面的任何子对象。当触摸条形图时,锁定回收器视图,使其不水平滚动,只允许条形图滚动,完成后允许RV滚动尝试此操作
    holder.horizontalScrollView.setOnTouchListener(new 
        View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            
     holder.horizontalScrollView.getParent().
      requestDisallowInterceptTouchEvent(true);


            return false;
        }
    });