在BottomSheetDialogFragment
中,无论BottomSheetBehavior
BottomSheetDialogFragment
是什么CoordinatorLayout
,我都想要一个始终贴在屏幕底部的视图。
在BottomSheetDialogFragment
的子类中,我从XML中扩展了一个视图,并将其添加为@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
setupBottomBar(getView());
}
private void setupBottomBar (View rootView) {
CoordinatorLayout parentView = (CoordinatorLayout) ((FrameLayout)rootView.getParent()).getParent();
parentView.addView(LayoutInflater.from(getContext()).inflate(R.layout.item_selection_bar, parentView, false), -1);
}
的子项(CoordinatorLayout
的父项父项):
BottomSheetDialogFragment
代码运行没有错误 当我使用Layout Inspector查看View层次结构时,视图结构也是正确的:
您还可以下载布局检查器结果,然后使用自己的Android Studio打开它。
但是,即使它作为BottomSheetDialogFragemnt
的最后一个子项插入,它仍然被BottomSheetDialog
阻止。
当我慢慢地向下滚动design_bottom_sheet
(从折叠状态到隐藏状态)时,我终于可以看到我想要在片段后面膨胀的视图。
为什么会这样?
正如@GoodDev正确指出的那样,这是因为根视图(design_bottom_sheet)已被private void setupBottomBar (View rootView) {
CoordinatorLayout parentView = (CoordinatorLayout) (rootView.getParent().getParent());
View barView = LayoutInflater.from(getContext()).inflate(R.layout.item_selection_bar, parentView, false);
ViewCompat.setTranslationZ(barView, ViewCompat.getZ((View)rootView.getParent()));
parentView.addView(barView, -1);
}
设置为Z翻译。
这提供了一个重要信息 - 不仅视图层次结构中的序列将决定其可见性,还会确定其Z可见性。
最好的方法是获取Option Explicit
Sub HideCharts()
Dim wb As Workbook
Dim wsData As Worksheet
Dim targetTable As ListObject
Set wb = ThisWorkbook
Set wsData = wb.Worksheets("Sheet1")
Set targetTable = wsData.ListObjects("Table1")
'Check that there are other values apart from 0 so don't try to filter to nothing
If Application.WorksheetFunction.CountIf(targetTable.DataBodyRange.Columns(2), ">" & 0) > 0 Then ' DataBodyRange.Columns(2) = y column
With targetTable.Range
.AutoFilter Field:=2 'remove filter
.AutoFilter Field:=2, Criteria1:="<>0", Operator:=xlFilterValues
End With
End If
End Sub
的Z值并将其设置为底栏设置。
Split$
答案 0 :(得分:2)
编辑2
好的,现在我看到了你的要求,试试这个:
private void setupBottomBar (View rootView) {
CoordinatorLayout parentView = (CoordinatorLayout) ((FrameLayout)rootView.getParent()).getParent();
View view = LayoutInflater.from(getContext()).inflate(R.layout.item_selection_bar, parentView, false);
// using TranslationZ to put the view on top of bottom sheet layout
view.setTranslationZ(100);
parentView.addView(view, -1);
}
修改强>
好的,我检查你的布局并查看BottomSheetDialogFragment
源代码,找到原因:
在使用BottomSheetDialogFragment
对话框的BottomSheetDialog
中,nl2br中的方法setContentView
使用BottomSheetDialog将内容视图置于R.id.design_bottom_sheet
布局中。因此,您需要覆盖BottomSheetDialogFragment
&#39; public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
来解决问题。
或者,将您的setupBottomBar
方法更改为:
private void setupBottomBar (View rootView) {
FrameLayout frame = (FrameLayout)rootView.getParent();
frame.addView(LayoutInflater.from(getContext()).inflate(R.layout.item_selection_bar, frame, false), -1);
}
并在您的item_selection_bar
布局文件中,更改高度和layout_gravity:
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_gravity="bottom"
android:layout_width="match_parent"
android:layout_height="wrap_content">
wrapInBottomSheet
doc说:模态底页。这是DialogFragment的一个版本,它使用BottomSheetDialog
而不是浮动对话框显示底部工作表。
因此BottomSheetDialogFragment
是Dialog
,Dialog
是一个浮动视图,因此会在BottomSheetDialogFragment
显示时覆盖活动内容。
答案 1 :(得分:1)
@goodev给出了一个很好的答案。
查看Z
位置会导致此问题。虽然TextView是最后一个位置,但您仍然无法看到它。
您可以将design_sheet_bottom's Z
设置为TextView。
private void setupBottomBar (View rootView) {
CoordinatorLayout parentView = (CoordinatorLayout) ((FrameLayout)rootView.getParent()).getParent();
View view = LayoutInflater.from(getContext()).inflate(R.layout.item_selection_bar, parentView, false);
view.setZ(((View)rootView.getParent()).getZ());
parentView.addView(view, -1);
}
我认为上面的方式非常无聊,您可以将两个视图RecyclerView
和TextView
放入布局吗?然后,您可以使用onCreateView()
方法将主题一起膨胀。