android - BottomSheetBehavior 与两个 RecyclerView

标签 android android-layout android-recyclerview bottom-sheet

我在带有 BottomSheetBehavior 的 LinearLayout 中得到了两个 RecyclerView。当您单击第一个 RecyclerView(带有网格)内的项目时,RecyclerView 将设置为 Gone 并显示第二个 RecyclerView(带有列表)。当显示第二个 Recycler 时,您无法上下滑动 BottomSheet,而是即使在展开状态下列表也在滚动。如果 First Recycler 已启动,则一切正常。有没有办法让BottomSheet再次上下滑动?

<LinearLayout
        android:id="@+id/sliding_layout_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:orientation="vertical"
        app:behavior_hideable="false"
        app:behavior_peekHeight="400dp"
        app:layout_behavior="@string/bottomSheetBehavior">

        <android.support.v7.widget.RecyclerView 
           android:id="@+id/grid"
           android:layout_width="match_parent"
           android:layout_height="match_parent"
           android:layout_marginEnd="@dimen/activity_horizontal_margin"
           android:layout_marginStart="@dimen/activity_horizontal_margin"
           android:background="@color/white"
           android:clickable="true"
           android:scrollbars="none" />

        <android.support.v7.widget.RecyclerView 
           android:id="@+id/list"
           android:layout_width="match_parent"
           android:layout_height="match_parent"
           android:layout_marginEnd="@dimen/activity_horizontal_margin"
           android:layout_marginStart="@dimen/activity_horizontal_margin"
           android:background="@color/white"
           android:clickable="true"
           android:scrollbars="none" />
</LinearLayout>

网格适配器:

   @Override
   public void onBindViewHolder(ViewHolder holder, int position) {

    String categorieName = mCategories.get(position);
    final CategoryFilterEvent event = new   CategoryFilterEvent(categorieName);
    holder.grid_item_label.setText(categorieName);

    holder.itemView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            EventBus.getDefault().post(event);
        }
    });
}

主要 Activity :

 @Override
 public void onCreate(Bundle savedInstanceState) {

    linearLayoutManager = new LinearLayoutManager(this);
    listAdapter = new ListAdapter(this, mList);
    recyList.setAdapter(listAdapter);
    recyList.setLayoutManager(linearLayoutManager);

    gridLayoutManager = new GridLayoutManager(this, 3);
    gridAdapter = new GridAdapter(this, new ArrayList<String>());
    recyGrid.setAdapter(gridAdapter);
    recyGrid.setLayoutManager(gridLayoutManager);
}

public void onEventMainThread(CategoryFilterEvent event) {
    recyGrid.setVisibilty(GONE);
    recyList.setVisiblity(VISIBLE);
}

最佳答案

您是否在 BottomSheetDialogFragment 中有两个 recyclerView(第一个 - 水平,第二个 - 垂直)和第二个不可滚动的 recyclerView?在为它设置适配器后,只需将其添加第一个回收器:

ViewCompat.setNestedScrollingEnabled(recyclerView1, false)

关于android - BottomSheetBehavior 与两个 RecyclerView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42159473/

相关文章:

android - 空 editText 上的 clearFocus() 在 Android 中不起作用

android - 适用于 Android 的可触摸图表库

android - GridLayout 和 LinearLayout 都在一个 RecyclerView 中

android - 进度对话框在低于和等于 API 级别 9 Android 时显示不佳

android - 使按钮/ View 出现在滚动条上

java - RecyclerView中的ImageButton

android - 在android中更改/删除底部栏的项目

java - PHP 脚本服务器端不向 Android 应用程序返回任何内容

java - 动态添加 View 或膨胀布局到 RecyclerView 的项目

android - RecyclerView 中具有动态项目宽度的水平滚动