我正在处理需要布局的应用程序,如下所述。
布局中有四个部分,我们说布局A,B,C和D.
布局D 已隐藏,并在向上滚动时显示一些其他效果。
同样在向下滚动时,首先 Layout-D 向下滚动,然后会出现 Layout-B 。进一步向下滚动布局-D 会隐藏,布局-C 会再次显示淡出效果。
我已经花了两天时间尝试使用带有协调器布局的BottomSheet,但无法实现精确效果。此外,BottomSheet滚动效果并不平滑,即如果出现并突然隐藏。
我想要使用的另一件事是具有协调器布局的自定义行为,但不确定如何继续。
答案 0 :(得分:1)
从父活动或片段中使用具有底部工作表行为的片段:
<android.support.design.widget.CoordinatorLayout
android:id="@+id/bottomsheetfragmenCoordinatorLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorBlackOpacity"
android:clickable="true"
>
<android.support.constraint.ConstraintLayout
android:id="@+id/bottomsheetfragmentLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:behavior_hideable="true"
app:behavior_peekHeight="50dp"
app:elevation="4dp"
app:layout_behavior="@string/bottom_sheet_behavior">
<fragment
android:id="@+id/bottomsheetfragment"
android:name="com.example.inslem.it.BottomSheet"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent" />
</android.support.constraint.ConstraintLayout>
</android.support.design.widget.CoordinatorLayout>
底片片段:
public class BottomSheet extends Fragment {
public BottomSheet() {
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_bottom_sheet, container, false);
return view;
}
@Override
public void onViewCreated(@NonNull final View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
}
}
并从父活动或父片段中获取 得到底页
@Override
public void onViewCreated(@NonNull final View view, @Nullable Bundle savedInstanceState) {
bottomsheetfragmenCoordinatorLayout = view.findViewById(R.id.bottomsheetfragmenCoordinatorLayout);
behavior = BottomSheetBehavior.from(bottomsheetfragmentLayout);
behavior.setPeekHeight(250);
behavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
@Override
public void onStateChanged(@NonNull View bottomSheet, int newState) {
switch (newState) {
case BottomSheetBehavior.STATE_DRAGGING:
break;
case BottomSheetBehavior.STATE_SETTLING:
break;
case BottomSheetBehavior.STATE_EXPANDED:
break;
case BottomSheetBehavior.STATE_COLLAPSED:
break;
case BottomSheetBehavior.STATE_HIDDEN:
break;
}
}
@Override
public void onSlide(@NonNull View bottomSheet, float slideOffset) {
Log.i("BottomSheetCallback", "slideOffset: " + slideOffset);
}
});
}