The view is in the last position of the parent, but still locked

What i want to do

In BottomSheetDialogFragment, I want to inflate a view that will always adhere to the bottom of the screen, regardless of what state (collapse / expand) is BottomSheetBehavior.

What I've done

In a subclass, BottomSheetDialogFragmentI inflate a view from XML and add it as a child CoordinatorLayout(which is the BottomSheetDialogFragmentparent):

@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);
}

The code works without errors.
And when I use the Layout Inspector to view the View hierarchy, the view structure is also correct:

Screenshot of the layout installer

You can also download the result of the layout inspector here and open it using your own Android studio.

Problem

, CoordinatorLayout, BottomSheetDialogFragment.
BottomSheetDialogFragemnt ( ), , .

Open blocked

?

@GoodDev, , (design_bottom_sheet) Z BottomSheetDialog.
, , Z.

- Z 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);
}
+4
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);
}

EDIT:

, BottomSheetDialogFragment, :

BottomSheetDialogFragment, BottomSheetDialog, setContentView BottomSheetDialog, wrapInBottomSheet, R.id.design_bottom_sheet. BottomSheetDialogFragment 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">

BottomSheetDialogFragment doc : . DialogFragment, , BottomSheetDialog .

, BottomSheetDialogFragment Dialog, Dialog , Activity, BottomSheetDialogFragment.

+2

@goodev .

Z . TextView , .

enter image description hereenter image description here

design_sheet_bottom 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().

+2

Source: https://habr.com/ru/post/1694220/


All Articles