我在带有 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/