1

I have searched in similar questions and tried several answer without solving .. I have Horizontal Recycler View displaying city names and some data the problem is that I put canvas bar chart or RV chart as figure below inside Main Recycler View adapter at every position and to scroll this chart horizontally I put the chart in Horizontal Scroll View to see data of chart in long Horizontal direction while scrolling this chart from right to left and vise versa but actually it doesn't scroll Horizontal only Main Recycler view scroll Horizontal to display city when touch it and for this chart inside RV didn't scroll when touch it to scroll (freeze) is recycler view only scroll in horizontal and prevent any other scroll inside its child??

enter image description here

here is my recycler view item layout

<?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>

I have tried to make Recycler View layout manger scroll vertically and the horizontal chart succeed to scroll horizontal but when make RV Horizontal the chart freeze without scrolling although it is inside Horizontal Scroll View

here is my RV

  recyclerViewWeather.setLayoutManager(new LinearLayoutManager(this, RecyclerView.HORIZONTAL, 
  false));
    adapter = new WeatherAdapter(this, cityList, dataManager);
   recyclerViewWeather.setHasFixedSize(true);
    recyclerViewWeather.setAdapter(adapter);

   recyclerViewWeather.addOnScrollListener(new RecyclerView.OnScrollListener() {
        @Override
        public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
            super.onScrollStateChanged(recyclerView, newState);
            if (newState == RecyclerView.SCROLL_STATE_IDLE){
               position = getCurrentItem();
               

                try {
                    UpdateDailyWeather();
                } catch (JSONException e) {
                    e.printStackTrace();
                }

            }
        }
    });
    PagerSnapHelper snapHelper = new PagerSnapHelper();
    snapHelper.attachToRecyclerView(recyclerViewWeather);
Wael Youssef
  • 49
  • 1
  • 10

2 Answers2

1

Wrap your WeatherChartViewBars in Horizontal LinearLayout inside HorizontalScrollView. It will work.

Brendon
  • 1,368
  • 1
  • 12
  • 28
  • thank you.. it doesn't work on emulator but I tried in actual device it work very slowly and freeze moving Bar chart horizontally . I mean bar chart freeze and city recycler view scroll horizontal instead so the result bar chart scroll very slow or freeze when trying to scroll it in horizontal and if I make RV vertical it work good scrolling bar horizontal – Wael Youssef May 31 '21 at 11:09
  • Not yet I think to make recycler view Linear Layout Manager HORIZONTAL prevent any horizontal scroll inside it even I put this bar chart in Horizontal Scroll View the main RV only scroll in horizontal and freeze scrolling any child inside it – Wael Youssef May 31 '21 at 12:25
  • is there away when touch bar chart lock recycler view from scrolling horizontally and allow only bar chart scroll and after finish that allow RV scroll – Wael Youssef May 31 '21 at 12:29
  • Try this https://stackoverflow.com/questions/59973757/nested-recyclerview-not-scrolling – Brendon May 31 '21 at 12:34
  • I think it is near to what i want but solution seems to be wrong or unclear, may be i must stop parent recyclerview from scrolling while touching child recyclerview items but i don't know how to implement – Wael Youssef Jun 04 '21 at 16:29
  • thanks so much it helped and fixed scrolling horizontal scroll view in Horizontal Recycler view – Wael Youssef Jun 05 '21 at 09:47
1

@Brendon put me on the right way as I must stop Scrolling in Horizontal Recycler view while touching Horizontal scroll view items like Bar chart the key is getparent of horizontal scroll view. Also I did it for every item in adapter view holder that want to scroll it horizenttaly

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

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


            return false;
        }
    });
Wael Youssef
  • 49
  • 1
  • 10