0

我在ViewPager的Fragment中有一個RecyclerView。 RecyclerView中的每個項目都是一個LinearLayout。我的問題是,當我觸摸RecyclerView時,我無法滑動頁面。我用RelativeLayout嘗試過它,它的工作原理是LinearLayout。ViewPager中的LinearLayout禁用了滑動操作

我的片段佈局:

<android.support.v7.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" android:layout_height="match_parent" 
    /> 

行佈局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="wrap_content" 
    android:weightSum="1"> 
    <TextView 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="0.05" 
     android:textAlignment="center" 
     android:id="@+id/game_all_text_number" 
     android:singleLine="true" 
     android:ellipsize="marquee" 
     android:marqueeRepeatLimit="marquee_forever" 
     /> 
    <TextView 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="0.225" 
     android:textAlignment="center" 
     android:id="@+id/game_all_text_player1" 
     android:singleLine="true" 
     android:ellipsize="marquee" 
     android:marqueeRepeatLimit="marquee_forever" 
     /> 
    <TextView 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="0.225" 
     android:textAlignment="center" 
     android:id="@+id/game_all_text_player2" 
     android:singleLine="true" 
     android:ellipsize="marquee" 
     android:marqueeRepeatLimit="marquee_forever" 
     /> 
    <TextView 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="0.225" 
     android:textAlignment="center" 
     android:id="@+id/game_all_text_player3" 
     android:singleLine="true" 
     android:ellipsize="marquee" 
     android:marqueeRepeatLimit="marquee_forever" 
     /> 
    <TextView 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="0.225" 
     android:textAlignment="center" 
     android:id="@+id/game_all_text_player4" 
     android:singleLine="true" 
     android:ellipsize="marquee" 
     android:marqueeRepeatLimit="marquee_forever" 
     /> 
    <TextView 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="0.05" 
     android:textAlignment="center" 
     android:id="@+id/game_all_text_diff" 
     android:singleLine="true" 
     android:ellipsize="marquee" 
     android:marqueeRepeatLimit="marquee_forever" 
     /> 
</LinearLayout> 

如果我改變該行的父RelativeLayout的,我可以刷卡,它工作得很好,但它不,如果它是一個LinearLayout。

我根本不需要點擊RecyclerView,有沒有辦法讓RecyclerView上的任何滑動或任何觸摸事件都可以被禁用,而是發送到片段?

回答

1

嘗試設置

android:clickable="false" 
android:focusable="false" 
android:focusableInTouchMode="false" 
在RecyclerView

或項目的LinearLayout

+0

它沒有工作。我試着單獨在RecyclerView上設置它,然後在LinearLayout上單獨設置,然後在兩者上都沒有任何工作,我仍然無法滑動到頁面。 –