在每种状态下,如何在Bottom-Sheet的底部显示编辑文本?

时间:2019-04-15 12:02:08

标签: java android bottom-sheet

我喜欢在底页中集成评论部分。在Comment部分,我有显示所有评论的recyclerView和位于视图底部的EditText。当在折叠状态下打开底页时,不显示编辑文本,而在状态为展开时,显示编辑文本布局。所以我需要帮助才能在每种状态下显示“编辑文本”选项。

This is Collapsed state Image

This is Expanded State Image

我想在“收合状态”下显示“编辑文本”,就像“心情扩大”一样。

  

XML布局

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    tools:context=".fragment.CommentFragment">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <android.support.v4.widget.NestedScrollView
            android:id="@+id/nested_scroll_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:scrollbars="none"
            android:scrollingCache="true">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:descendantFocusability="blocksDescendants"
                android:orientation="vertical">

                <android.support.v7.widget.RecyclerView
                    android:id="@+id/rv_main"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">

                </android.support.v7.widget.RecyclerView>

                <View
                    android:layout_width="fill_parent"
                    android:layout_height="?attr/actionBarSize">
                </View>

            </LinearLayout>

        </android.support.v4.widget.NestedScrollView>

    </LinearLayout>

    <LinearLayout
        android:orientation="vertical"
        android:background="#fff"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true">
        <View
            android:background="#B1B1B1"
            android:layout_width="match_parent"
            android:layout_height="1dp"/>
        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
    </LinearLayout>




</RelativeLayout>
  

代码

@Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        final BottomSheetDialog dialog = (BottomSheetDialog) super.onCreateDialog(savedInstanceState);
        dialog.getWindow().setSoftInputMode(
                WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE|
                        WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
        final View view = View.inflate(getContext(), R.layout.fragment_comment, null);
        unbinder = ButterKnife.bind(this, view);
        dialog.setContentView(view);
        mBehavior = BottomSheetBehavior.from((View) view.getParent());
        mBehavior.setPeekHeight(BottomSheetBehavior.PEEK_HEIGHT_AUTO);
        mBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);

        mBehavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
            @Override
            public void onStateChanged(@NonNull View bottomSheet, int newState) {
                if (BottomSheetBehavior.STATE_EXPANDED == newState) {
                    Log.d(TAG, "onStateChanged: STATE_EXPANDED");
                }
                if (BottomSheetBehavior.STATE_COLLAPSED == newState) {
                    Log.d(TAG, "onStateChanged: STATE_COLLAPSED");
                }

                if (BottomSheetBehavior.STATE_HIDDEN == newState) {
                    Log.d(TAG, "onStateChanged: STATE_HIDDEN");
                    dismiss();
                }
            }

            @Override
            public void onSlide(@NonNull View bottomSheet, float slideOffset) {

            }
        });

        commentsAdapterNew = new CommentsAdapterNew(getActivity(), commentsClassList);
        RecyclerView.LayoutManager mManager = new LinearLayoutManager(getActivity(), RecyclerView.VERTICAL, true);
        rvMain.setLayoutManager(mManager);
        rvMain.setAdapter(commentsAdapterNew);
        ViewCompat.setNestedScrollingEnabled(rvMain, false);

        getAllComment("876");

        return dialog;
    }

0 个答案:

没有答案