Как сделать так, чтобы BottomSheetDialogFragment отображался в верхней части BottomNavigationView, и как сделать так, чтобы он отображался под BottomNavigationView - PullRequest
0 голосов
/ 11 июня 2019

BottomSheetFragment Collapsed in Top of BottomNavigationView

Я пытаюсь сделать так, чтобы BottomSheetDialogFragment отображался в верхней части BottomNavigationView и ниже BottomNavigationView, то есть с более низкой отметкой.В BottomSheetDialogFragment будет представлен видеоплеер, похожий на YouTube, с RecyclerView, который может развернуть и свернуть нижнюю таблицу.Я уже исследовал несколько предложений и ничего не решил.Включая Stackoverflow.Я попробовал два варианта метода Show () согласно приведенному ниже коду - но ни один из них не сработал.Я могу делать Expand, Collapsed и другие действия, не беспокойтесь об этом.Проблема состоит в том, чтобы создать BottomSheet за BottomNavigationView и над RecyclerView действия.

CODE ACTIVITY

открытый класс myController расширяет CommonActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //inflate the layout of the activity
    setContentView(R.layout.controller_layout);
    //other activity codes
    //progressBar = findViewById(R.id.progressBar);
    //contains initialization codes for views and recyclerview
    //initViews();
}

OPTION 01: It's the CALL that everyone is pointing to BottomSheetDilogFragment, except BottomSheet is over BottomNavigationView
INITIALIZED when clicking on a item (thumbnail) of a RecyclerView in the layout of the activity/fragment
  public void initBottomSheet(Bundle b){
    VideoViewBottomSheet fragment = new VideoViewBottomSheet();
    fragment.setArguments( b );
    fragment.show( getSupportFragmentManager(), VideoViewBottomSheet.FRAGMENT_KEY );}

OPTION 02: I tried this option for BottomSheetDilogFragment, in it the BottomSheet is 
DOWN of the BottomNavigationView, BUT behave like a NORMAL FRAGMENT and not as BottomSheetDilogFragment, DO NOT EXPAND, DO NOT COLLAPSE, NOTHING.
  public void initBottomSheet(Bundle b){
    VideoViewBottomSheet fragment = new VideoViewBottomSheet();
    fragment.setArguments( b );
    FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
    ft.add(R.id.bottom_sheet_loyout, fragment);
    ft.commit();
}

}

CODE BottomSheetFragment

@Override
public void onStart() {
    super.onStart();
    Dialog dialog = getDialog();

    if (dialog != null) {
        View view = getView();
        final View parent = (View) view.getParent();
        final View bottomSheet = dialog.findViewById(R.id.rv_bottom_sheet);
        final View videoView = bottomSheet.findViewById(R.id.videoView);
        final View bottom_nav_view = getActivity().findViewById(R.id.bottom_nav_view);
        final int screenHeight = ViewGroup.LayoutParams.MATCH_PARENT;
        final View relativeLayout = getActivity().getWindow().getDecorView().getRootView().findViewById(R.id.relativelayout);
        final View coodinatorLayout = getActivity().getWindow().getDecorView().getRootView().findViewById(R.id.coordinatorlayout);

        CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) (parent).getLayoutParams();
        CoordinatorLayout.Behavior behavior = params.getBehavior();

        parent.setFitsSystemWindows(false);
        bottomSheet.getLayoutParams().height = screenHeight;
        params.gravity = Gravity.TOP | Gravity.CENTER_HORIZONTAL;

        final BottomSheetBehavior bottomSheetBehavior = (BottomSheetBehavior) behavior;
        bottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);

        if (bottomSheetBehavior instanceof BottomSheetBehavior) {
            offsetY = 0;
            ((BottomSheetBehavior) bottomSheetBehavior).setBottomSheetCallback(
            new BottomSheetBehavior.BottomSheetCallback() {

                @Override
                public void onSlide(@NonNull View bottomSheet, float slideOffset) {
                    if(slideOffset>0.2 ){
                        bottomSheetBehavior.setHideable(false);
                        bottomSheetBehavior.setPeekHeight(bottom_nav_view.getHeight()+56 );
                        bottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
                        parent.setPadding(0,0,0,bottom_nav_view.getHeight()+56);
                        parent.setBackgroundColor(Color.GREEN);
                        bottom_nav_view.setVisibility(View.VISIBLE);
                        bottom_nav_view.setBackgroundColor(Color.YELLOW);
                    }
                    offsetY = slideOffset;
                }

                @Override
                public void onStateChanged(@NonNull View bottomSheet, int newState) {
                }
            });
        }
    }
}

Ожидаемый результатэто BottoSheet, похожий на тот, что используется в Youtube Player.То есть BottomSheet, который содержит Fracyc ReViewlerView и воспроизводит видео.

XMLS

mycontroller_layout.xml
-----------------------
<RelativeLayout
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/relativelayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent"
android:fitsSystemWindows="false"
tools:context=".myController">

<android.support.design.widget.CoordinatorLayout
    android:id="@+id/coordinatorlayout"
    android:layout_above="@+id/bottom_nav_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:fitsSystemWindows="false">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay">
        </android.support.v7.widget.Toolbar>

    </android.support.design.widget.AppBarLayout>

    <ProgressBar
        android:id="@+id/progressBar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_centerInParent="true"
        android:layout_centerHorizontal="true"
        android:layout_gravity="center_vertical|center_horizontal"
        android:visibility="gone" />

    <include layout="@layout/content" />

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/bottomsheet"/>

</android.support.design.widget.CoordinatorLayout>

<android.support.design.widget.BottomNavigationView
    android:id="@+id/bottom_nav_view"
    android:layout_below="@+id/coordinatorlayout"
    android:layout_width="match_parent"
    android:layout_height="56dp"
    android:elevation="50dp"
    android:visibility="visible"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    app:itemIconTint="@color/colorWhite"
    android:background="@color/colorPrimary"
    app:menu="@menu/activity_main_bottom" />
</RelativeLayout>

content.xml
-----------
<RelativeLayout
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/container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingTop="4dp"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context=".RebootController"
tools:showIn="@layout/reboot_controller_layout">
<RelativeLayout
    android:id="@+id/containerContent"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >
</RelativeLayout>
</RelativeLayout>

bottom_sheet_loyout.xml
-------------------
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/rv_bottom_sheet"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/bottom_nav_view"
android:paddingLeft="4dp"
android:paddingRight="4dp"
android:elevation="3dp"
android:fitsSystemWindows="false"
android:orientation="vertical"
app:layout_behavior="@string/bottom_sheet_behavior" >
<RelativeLayout
    android:id="@+id/rlVideoView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true">

    <VideoView
        android:id="@+id/videoView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <android.support.v4.widget.SwipeRefreshLayout
        android:id="@+id/srl_swipe"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/videoView">
        <android.support.v7.widget.RecyclerView
            android:id="@+id/rv_list"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_alignParentTop="true"
            android:clipToPadding="false"
            android:paddingBottom="56dp"/>
    </android.support.v4.widget.SwipeRefreshLayout>

    <ProgressBar
        android:layout_width="40dp"
        android:layout_height="40dp"
        android:layout_gravity="center"
        android:visibility="gone" />
        <!--<LinearLayout
            anúncio google
        </LinearLayout>-->
</RelativeLayout>
</RelativeLayout>
...