0

我在我的主頁中有一個滾動視圖,滾動視圖內有2個佈局,每個佈局爲一個recyclerview,每個recyclerview將水平滾動。當我嘗試滾動回收站視圖時,滾動視圖的滾動正在進入,滾動視圖開始在垂直方向滾動。所以我嘗試了下面的代碼。滾動視圖中水平recyclerview的滾動問題

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,但現在的問題是我不能滾動我scrolview verticaly當我觸及recyclerviews。任何建議請。 我的確切需要是我需要滾動視圖和滾動視圖內幾個recyclerviews在那裏,它會像谷歌播放商店應用程序一樣工作。

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> 

+0

嘗試此鏈接https://stackoverflow.com/questions/39870099/dynamic-different-images-horizo​​ntal-recyclerview-in-vertical-recyclerview-like-g – Ankita

+0

也有看看這個http:// android -pratap.blogspot.in/2015/12/horizo​​ntal-recyclerview-in-vertical.html – Ankita

回答

0

你應該使用NestedScrollView insted的滾動型

NestedScrollView就像ScrollView一樣,但它支持在Android的新版本和舊版本中同時作爲嵌套滾動父代和子代。嵌套滾動默認啓用。

閱讀ScrollView vs NestedScrollView

,不要忘了讓你RecycelrveiwsetNestedScrollingEnabled(false);

setNestedScrollingEnabled(boolean enabled)

它啓用或禁用嵌套滾動的這一觀點。

代碼

YourRecyclerView.setNestedScrollingEnabled(false); 
+0

我應該在哪裏設置「YourRecyclerView.setNestedScrollingEnabled(false);」觸摸監聽器? – ranjith

+0

否@ranjith添加'YourRecyclerView。setNestedScrollingEnabled(false);'在將佈局管理器設置爲您的recyclerviw意味着綁定後 –

+0

我已經嘗試了這一點,但是我的設計有點複雜,就像整個scrollview在滑動面板佈局中一樣,我需要第一個佈局應該粘在頂部當他們到達頂部,這就是爲什麼我使用滑動面板佈局 – ranjith

0

,可以使用兩個再循環次(嵌套一個父垂直回收視圖內水平回收視圖)。它會更有效並且能夠平滑滾動。