Вложенный горизонтальный RecyclerView - PullRequest
0 голосов
/ 22 февраля 2019

Я хочу создать вложенный RecyclerView, если Parent RV - это горизонтальный менеджер компоновки с> 3 элементами, и дочерний элемент тоже horzinotl, но я не могу прокрутить дочерний элемент, это только указывает на родительский жест.

ParentLayoutManager

 LinearLayoutManager layoutManager = new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false);
    listItem.setLayoutManager(layoutManager);
    listItem.setAdapter(adapter);

Дочерний LayoutManager

 RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false);
    list.setHasFixedSize(true);
    list.setLayoutManager(layoutManager);
    list.setItemAnimator(new DefaultItemAnimator());
    list.setAdapter(adapter);

XML - родительский

  <androidx.cardview.widget.CardView
        android:id="@+id/card"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/list_item"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:clipToPadding="false" />

    </androidx.cardview.widget.CardView>

XML - родительский элемент

     <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/roundColor_svprogresshuddefault"
    android:elevation="160dp"
    android:padding="@dimen/home_cell_margin">


                <androidx.recyclerview.widget.RecyclerView
                    android:id="@+id/list_item"
                    android:layout_width="wrap_content"
                    android:layout_height="150dp"
                    android:layout_gravity="center"
                    android:nestedScrollingEnabled="false" />
 </androidx.constraintlayout.widget.ConstraintLayout>

XML - дочерний

<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/listHolder">
    <ImageView
        android:id="@+id/img"
        android:layout_width="match_parent"
        android:layout_height="match_parent" ></ImageView>
</LinearLayout>

Пример результата

Example

1 Ответ

0 голосов
/ 07 марта 2019

Я исправил это, создав простой пользовательский RecyclerView и ниже финального кода

public class DJHRecyclerView extends RecyclerView {
    public DJHRecyclerView(Context context) {
        super(context);
    }

    public DJHRecyclerView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public DJHRecyclerView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent event) {
        getParent().requestDisallowInterceptTouchEvent(true);
        return super.onInterceptTouchEvent(event);
    }

}
...