我正在处理应用程序,例如什么应用程序相机,我在gridview
中崩溃了bottomsheet behavior
有些困难。
我希望在没有预览任何项目并自上而下拖动时崩溃。
Android XML代码:
<android.support.design.widget.CoordinatorLayout
android:layout_marginBottom="100dp"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<ImageView
android:id="@+id/drag_arrow"
android:layout_width="match_parent"
android:layout_height="100dp"
android:paddingBottom="40dp"
android:paddingTop="10dp"
android:src="@mipmap/arrow_up"
app:layout_anchor="@+id/galleryGridView2" />
<GridView
android:id="@+id/galleryGridView2"
android:layout_width="match_parent"
android:layout_height="500dp"
android:background="#44000000"
android:columnWidth="120dp"
android:gravity="center"
android:horizontalSpacing="10dp"
android:numColumns="auto_fit"
android:stretchMode="columnWidth"
android:verticalSpacing="10dp"
app:layout_behavior="@string/bottom_sheet_behavior" />
</android.support.design.widget.CoordinatorLayout>
和JAVA代码:
BottomSheetBehavior mBottomSheetBehavior;
final GridView gallery;
gallery = (GridView) findViewById(R.id.galleryGridView2);
mBottomSheetBehavior = BottomSheetBehavior.from(gallery);
mBottomSheetBehavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
@Override
public void onStateChanged(@NonNull View bottomSheet, final int newState) {
if (newState == BottomSheetBehavior.STATE_COLLAPSED) {
mBottomSheetBehavior.setPeekHeight(100);
}
if (newState == BottomSheetBehavior.STATE_DRAGGING) {
mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
}
}
@Override
public void onSlide(@NonNull View bottomSheet, float slideOffset) {
}
});
mBottomSheetBehavior.setPeekHeight(100);
我在 stackOverFlow 上看到了类似的答案,例如:
gallery.setOnScroll(...)
if(!canScrollVertically(-1)) //Collapse
or checking if I'm on the top of gridview //Collapse
这些答案工作正常但问题是如果我快速向上滚动我无法看到gridview的顶部并且它会崩溃。
所以请任何建议, 提前谢谢。