Amr*_*dhu 5 java android android-studio bottom-sheet
我需要底页在两个位置停下来。我的底表有以下代码。
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
....
</RelativeLayout>
<FrameLayout
android:id="@+id/bottom_sheet"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="android.support.design.widget.BottomSheetBehavior">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:minHeight="1000dp"
android:orientation="vertical">
....
</LinearLayout>
</ScrollView>
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)
和
View bottomSheet = coordinatorLayout.findViewById(R.id.bottom_sheet);
final BottomSheetBehavior behavior = BottomSheetBehavior.from(bottomSheet);
behavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
@Override
public void onStateChanged(@NonNull View bottomSheet, int newState) {
// React to state change
Log.e("onStateChanged", "onStateChanged:" + newState);
if (newState == BottomSheetBehavior.STATE_EXPANDED) {
behavior.setPeekHeight(600);
showAgain.setVisibility(View.GONE);
mMap.getUiSettings().setScrollGesturesEnabled(false);
} else if (newState == BottomSheetBehavior.STATE_COLLAPSED) {
if (behavior.getPeekHeight() == 600) {
behavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
behavior.setPeekHeight(80);
mMap.getUiSettings().setScrollGesturesEnabled(false);
} else if (behavior.getPeekHeight() == 80) {
showAgain.setVisibility(View.VISIBLE);
mMap.getUiSettings().setScrollGesturesEnabled(true);
}
}
}
@Override
public void onSlide(@NonNull View bottomSheet, float slideOffset) {
// React to dragging events
Log.e("onSlide", "onSlide " + slideOffset);
}
});
behavior.setPeekHeight(600);
Run Code Online (Sandbox Code Playgroud)
除了一件事外,这段代码可以正常工作。第一次,我必须向上滚动底部表格,然后向下滚动。我不能直接向下滚动工作表。
任何帮助将不胜感激。
小智 6
您可以使用 与CoordinatorLayout配合更好的NestedScrollView,而不是使用滚动视图,请 确保使用app:layout_behavior="@string/appbar_scrolling_view_behavior"以平滑滚动 NestedScrollView 内的内容
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
}
}
}
Run Code Online (Sandbox Code Playgroud)
上述解决方案使用此链接对我有用:https : //code.tutsplus.com/articles/how-to-use-bottom-sheets-with-the-design-support-library--cms-26031
归档时间: |
|
查看次数: |
8226 次 |
最近记录: |