我有一个具有这种布局的BottomSheetDialogeFragment。我想滚动整个片段视图而不是只滚动gridview。我尝试了将LinearLayout与scrollview和NestedScrollView嵌套,但是在这两种情况下,模态甚至都不会滑动到顶部。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical">
<ImageView
android:background="@color/colorPrimary"
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/heart"
android:scaleType="fitXY"
android:adjustViewBounds="true"/>
<GridView
android:id="@+id/gridView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:stretchMode="columnWidth"
android:gravity="center"
android:numColumns="4" />
</LinearLayout>
尝试这个对我有用
mBottomSheetBehavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
@Override
public void onStateChanged(@NonNull View bottomSheet, int newState) {
if (newState == BottomSheetBehavior.STATE_COLLAPSED) {
mBottomSheetBehavior.setPeekHeight(0);
}
}
@Override
public void onSlide(@NonNull View bottomSheet, float slideOffset) {
}
});
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btn_negetive: {
mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
mBottomSheetBehavior.setPeekHeight(Constants.PEEK_HEIGHT);
mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
break;
}
case R.id.btn_positive: {
//some code
}
}
}