android - 我怎样才能创建这个布局?
问题描述
我正在开发需要如下所述布局的应用程序。
布局中有四个部分,比如说布局 A、B、C 和 D。
- 布局 A是 AppBar 并固定在顶部。
布局 D被隐藏并在向上滚动时出现,并带有一些附加效果。
- 向上滚动时,Layout-D从底部出现,而Layout-C开始褪色。
- 一切都保持原样,直到Layout-D与Layout-C完全重叠。
- 在Layout-D与Layout-C完全重叠后,进一步向上滚动Layout B开始向上滚动。
同样在向下滚动时,首先Layout-D向下滚动,然后Layout-B出现。进一步向下滚动时,Layout-D隐藏在下方,并且Layout-C再次出现并带有淡出效果。
我已经花了两天时间尝试将 BottomSheet 与 Coordinator 布局一起使用,但无法实现 Exact 效果。此外,BottomSheet 滚动效果不是那么平滑,即如果突然出现和隐藏。
我正在考虑使用的另一件事是使用协调器布局的自定义行为,但不确定如何继续。
解决方案
使用具有来自父活动或片段的底部工作表行为的片段:
<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);
}
});
}
推荐阅读
- javascript - Nightmarejs,点击文本,如果存在
- r - r- 将变量列表输入到矩阵中以进行 t.test
- azure - 具有 Blob 存储的 Azure Functions。如何为子文件夹创建 BlobTrigger?
- logstash - 通过 grok 过滤器解析日志
- r - 使用 dplyr 将输入从 Shiny 传递到 plotly 时,filter_imp 出错
- c++ - VSCode:调试时无法打开图像(C++/SFML)
- ios - 如何在 iOS 11+ 中录制 FLAC 格式
- c++ - 代码块编译错误与运算符 << 不匹配
- c# - Microsoft Bot Framework 通过键入“Reset”来重置 Bot 在 Azure 中不起作用
- python - 带有分组复选框的 Django 表单