有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java浮动操作按钮未在bottomsheetfragment折叠状态下显示

我有{}和{}按钮。我在{}中出现问题。“晶圆厂”按钮一出现,当我把底部的薄片展开到全屏时,我尝试了几种方法,但都不起作用

我在布局中尝试了不同的晶圆厂选项,以使其可见,但到目前为止运气不佳

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
    xmlns:app="http://schemas.安卓.com/apk/res-auto"
    xmlns:tools="http://schemas.安卓.com/tools"
    安卓:id="@+id/topBarBottomSheet"
    安卓:clipToPadding="true"
    安卓:layout_height="match_parent"
    安卓:layout_width="match_parent"
    >

    <FrameLayout
        安卓:layout_width="match_parent"
        安卓:layout_height="match_parent"
        安卓:layout_below="@id/topBarBottomSheet">
        <include layout="@layout/progressbar_framelayout" />

        <安卓x.recyclerview.widget.RecyclerView
            安卓:id="@+id/recycleviewGallery"
            安卓:layout_width="match_parent"
            安卓:layout_height="match_parent"
            安卓:clipToPadding="false"
            安卓:paddingTop="@dimen/list_item_spacing_half"
            安卓:paddingBottom="@dimen/list_item_spacing_half"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"
            tools:listitem="@layout/recycler_view_item_3"
            tools:spanCount="3"
            tools:layoutManager="GridLayoutManager" />



    </FrameLayout>
    <com.google.安卓.material.floatingactionbutton.FloatingActionButton
        安卓:id="@+id/fabBottomSheet"
        安卓:layout_width="wrap_content"
        安卓:layout_height="wrap_content"
        安卓:layout_margin="16dp"
        app:backgroundTint="@color/greenElaxer"
        app:fabSize="normal"
        app:srcCompat="@drawable/ic_check"
        安卓:layout_alignParentBottom="true"
        安卓:layout_alignParentRight="true"
        安卓:layout_alignParentEnd="true"

        安卓:overScrollMode="always"

         >

    </com.google.安卓.material.floatingactionbutton.FloatingActionButton>


</RelativeLayout>

BottomSheetFragment

public class BottomSheet extends BottomSheetDialogFragment {

    FloatingActionButton fab;
    RecyclerView recyclerView;
    // TODO: Customize parameters
    public static BottomSheet newInstance() {
        /*final Bundle args = new Bundle();
        args.putInt(ARG_ITEM_COUNT, itemCount);
        fragment.setArguments(args);*/

        return new BottomSheet();
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,@Nullable Bundle savedInstanceState) {

        return inflater.inflate(R.layout.fragment_bottemsheet_list_dialog, container, false);
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        recyclerView = view.findViewById(R.id.recycleviewGallery);
        fab = view.findViewById(R.id.fabBottomSheet);     
      BottomSheetAdapter bottomSheetAdapter = new BottomSheetAdapter();
      GridLayoutManager gridLayoutManager=new GridLayoutManager(getActivity(),2);
        recyclerView.setLayoutManager(gridLayoutManager);
        recyclerView.setHasFixedSize(true);
        recyclerView.setAdapter(bottomSheetAdapter);
    }


    @NonNull
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        BottomSheetDialog dialog = (BottomSheetDialog) super.onCreateDialog(savedInstanceState);
        dialog.setOnShowListener(new DialogInterface.OnShowListener() {
            @Override
            public void onShow(DialogInterface dialog) {
                //Get the BottomSheetBehavior
                BottomSheetDialog d = (BottomSheetDialog) dialog;
                FrameLayout bottomSheet = d.findViewById(com.google.安卓.material.R.id.design_bottom_sheet);
                if (bottomSheet != null) {
                    bottomSheet.getLayoutParams().height = ViewGroup.LayoutParams.MATCH_PARENT;
                    bottomSheetBehavior = BottomSheetBehavior.from(bottomSheet);
                    bottomSheet.setMinimumHeight(350);
                    bottomSheetBehavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
                        @Override
                        public void onStateChanged(@NonNull View view, int i) {
                            switch (i){
                                case BottomSheetBehavior.STATE_COLLAPSED:
                                    Log.d(TAG,"Collapsed");

                                    break;
                                case BottomSheetBehavior.STATE_DRAGGING:
                                    Log.d(TAG,"Dragging");

                                    break;
                                case BottomSheetBehavior.STATE_EXPANDED:
                                    Log.d(TAG,"Expanded");

                                    break;
                                case BottomSheetBehavior.STATE_HALF_EXPANDED:
                                    Log.d(TAG,"Half Expanded");
                                    break;
                                case BottomSheetBehavior.STATE_HIDDEN:
                                    Log.d(TAG,"Hidden");
                                    dismiss();
                                    break;
                                case BottomSheetBehavior.STATE_SETTLING:
                                    Log.d(TAG,"Settling");
                                    break;

                            }
                        }

                        @Override
                        public void onSlide(@NonNull View view, float v) {

                        }
                    });
                }
            }
        });

        return dialog;
    }

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        final Fragment parent = getParentFragment();
        Log.d(TAG,"Parent = "+parent+" Context "+context);
        if (parent != null) {
            mListener = (Listener) parent;
        } else {
            mListener = (Listener) context;
        }
    }

    @Override
    public void onDetach() {
        mListener = null;
        super.onDetach();
    }


}

每当我折叠底部板材时,fab按钮也会与底部板材一起向下移动。我需要使我的晶圆厂按钮坚持在同一个地方,无论我扩大或折叠底部表。提前谢谢

我需要坚持相同的布局(相对布局)


共 (1) 个答案

  1. # 1 楼答案

    当您退出某个片段时,无法使该片段中的UI元素保持不变。如果折叠底部工作表,则其所有UI元素都将折叠。你不能在原地不动

    您可以编写一个重复的fab,在关闭底层片段的底部之后显示

    例如,我在底部工作表中有此代码以退出底部工作表对话框

    nextButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mBottomSheetDialog.dismiss();
                mTimePickerDialogController.show(0, 0, makeTimePickerDialogTag());
            }});
    

    当您关闭底部表单时,您可以使用以下代码使基础片段中的fab出现或消失

    mFloatingActionButton.hide();
    mFloatingActionButton.show();
    

    编辑:处理第二个晶圆厂的更好解决方案

    BottomSheetBehavior sheetBehavior;
        sheetBehavior = BottomSheetBehavior.from(yourBottomSheet);
    
        sheetBehavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
            @Override
            public void onStateChanged(@NonNull View bottomSheet, int newState) {
                switch (newState) {
                    case BottomSheetBehavior.STATE_HIDDEN:
                        mFloatingActionButton.show();
                    case BottomSheetBehavior.STATE_EXPANDED: {
                        mFloatingActionButton.hide();
                    }
                    break;
                    case BottomSheetBehavior.STATE_COLLAPSED: {
                        mFloatingActionButton.show();
                    }
                }
            }