来自Android Design Support Library的Android底部表格正确行为

时间:2016-03-08 17:52:22

标签: android dialog android-support-library android-design-library android-appbarlayout

我正在尝试从新的Android设计支持库23.2.0实现BottomSheetDialog。我有layout GoogleMap FragmentToolbar和几个晶圆厂。

问题

接下来是问题:展开BottomSheetDialog并向上滚动NestedScrollView时,BottomSheetDialog不会崩溃,只有当我AppBarLayout BottomSheetDialog时,它才会崩溃1}}下来。我想要展开BottomSheetDialog滚动NestedScrollView

问题#2

如何创建这样的BottomSheetDialog

enter image description here

我的代码

我的BottomSheetBehavior

View bottomSheet = rootView.findViewById(R.id.bottom_sheet);
        BottomSheetBehavior bottomSheetBehavior = BottomSheetBehavior.from(bottomSheet);
        bottomSheetBehavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
            @Override
            public void onStateChanged(@NonNull View bottomSheet, int newState) {
                Log.d(TAG, "setUpMap() -> onStateChanged() -> newState: " + newState);
            }

            @Override
            public void onSlide(@NonNull View bottomSheet, float slideOffset) {
                Log.d(TAG, "setUpMap() -> onSlide() -> slideOffset: " + slideOffset);
            }
        });

        bottomSheetBehavior.setPeekHeight((int) Utils.convertDpToPixel(100f, this));

我的XML:

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:fab="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/root_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MapsActivity">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/toolbar">

        <fragment xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:tools="http://schemas.android.com/tools"
            android:id="@+id/map"
            android:name="com.google.android.gms.maps.SupportMapFragment"
            class="com.google.android.gms.maps.MapFragment"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            tools:context="ua.nau.edu.NAU_Guide.MapsActivity"
            tools:layout="@layout/fragment_maps" />

    </RelativeLayout>

    <android.support.design.widget.AppBarLayout
        android:id="@+id/app_bar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <include
            android:id="@+id/toolbar"
            layout="@layout/toolbar" />
    </android.support.design.widget.AppBarLayout>

    <com.github.clans.fab.FloatingActionMenu
        android:id="@+id/fab_menu"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="16dp"
        android:layout_marginLeft="16dp"
        android:layout_marginRight="16dp"
        android:layout_marginTop="16dp"
        app:layout_anchor="@id/map"
        app:layout_anchorGravity="bottom|right|end"
        fab:menu_colorNormal="@color/colorAppPrimary"
        fab:menu_colorPressed="@color/colorAppPressed"
        fab:menu_colorRipple="@color/colorAppRipped"
        fab:menu_icon="@drawable/ic_add_white_24dp"
        fab:menu_labels_position="left"
        fab:menu_openDirection="up"
        fab:menu_shadowRadius="1dp">

        <com.github.clans.fab.FloatingActionButton
            android:id="@+id/fab_route"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="8dp"
            android:layout_marginEnd="8dp"
            android:layout_marginRight="8dp"
            android:src="@drawable/ic_navigation_white_24dp"
            fab:fab_colorNormal="@color/colorAppPrimary"
            fab:fab_colorPressed="@color/colorAppPressed"
            fab:fab_colorRipple="@color/colorAppRipped"
            fab:fab_shadowRadius="1dp"
            fab:fab_size="mini" />

        <com.github.clans.fab.FloatingActionButton
            android:id="@+id/fab_info"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="8dp"
            android:layout_marginEnd="8dp"
            android:layout_marginRight="8dp"
            android:src="@drawable/ic_info_outline_white_24dp"
            fab:fab_colorNormal="@color/colorAppPrimary"
            fab:fab_colorPressed="@color/colorAppPressed"
            fab:fab_colorRipple="@color/colorAppRipped"
            fab:fab_shadowRadius="1dp"
            fab:fab_size="mini" />

        <com.github.clans.fab.FloatingActionButton
            android:id="@+id/fab_location"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="8dp"
            android:layout_marginEnd="8dp"
            android:layout_marginRight="8dp"
            android:src="@drawable/ic_map_white_24dp"
            fab:fab_colorNormal="@color/colorAppPrimary"
            fab:fab_colorPressed="@color/colorAppPressed"
            fab:fab_colorRipple="@color/colorAppRipped"
            fab:fab_shadowRadius="1dp"
            fab:fab_size="mini" />

    </com.github.clans.fab.FloatingActionMenu>

    <io.codetail.widget.RevealFrameLayout
        android:id="@+id/reveal_recycler"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="?attr/actionBarSize">

        <android.support.v7.widget.RecyclerView
            android:id="@+id/recyclerview_search"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/recyclerview_background"
            android:visibility="invisible" />

    </io.codetail.widget.RevealFrameLayout>

    <FrameLayout
        android:id="@+id/bottom_sheet"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/red"
        android:fitsSystemWindows="true"
        app:behavior_hideable="true"
        app:layout_behavior="android.support.design.widget.BottomSheetBehavior">

        <android.support.design.widget.CoordinatorLayout
            android:id="@+id/root_view_bsheet"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/material_drawer_primary"
            android:fitsSystemWindows="true">

            <android.support.design.widget.AppBarLayout
                android:id="@+id/app_bar_bsheet"
                android:layout_width="match_parent"
                android:layout_height="100dp"
                android:background="@color/colorAppPrimary"
                android:fitsSystemWindows="true"
                android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
                app:elevation="0dp">

                <android.support.design.widget.CollapsingToolbarLayout
                    android:id="@+id/collapsing_toolbar"
                    android:layout_width="match_parent"
                    android:layout_height="100dp"
                    android:fitsSystemWindows="true"
                    app:collapsedTitleTextAppearance="@android:color/transparent"
                    app:contentScrim="@color/colorAppPrimary"
                    app:expandedTitleTextAppearance="@android:color/transparent"
                    app:layout_scrollFlags="scroll|exitUntilCollapsed"
                    app:title="">

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

                        <TextView
                            android:id="@+id/app_bar_bsheet_title"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_marginTop="24dp"
                            android:paddingLeft="24dp"
                            android:paddingStart="24dp"
                            android:text="Bottom Sheet Title"
                            android:textColor="@color/white"
                            android:textSize="20sp" />

                        <TextView
                            android:id="@+id/app_bar_bsheet_subtitle"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_marginTop="4dp"
                            android:paddingLeft="24dp"
                            android:paddingStart="24dp"
                            android:text="Bottom Sheet Subtitle"
                            android:textColor="@color/white"
                            android:textSize="16sp" />

                    </LinearLayout>

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

            <android.support.v4.widget.NestedScrollView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                app:layout_behavior="@string/appbar_scrolling_view_behavior">

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

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

            <android.support.design.widget.FloatingActionButton
                android:id="@+id/fab_route_bsheet"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="top"
                android:layout_marginEnd="16dp"
                android:layout_marginRight="16dp"
                android:layout_marginTop="-24dp"
                android:clickable="true"
                android:src="@drawable/ic_directions_walk_white_24dp"
                app:backgroundTint="?attr/colorAccent"
                app:fabSize="normal"
                app:layout_anchor="@id/app_bar_bsheet"
                app:layout_anchorGravity="top|right|end"
                app:useCompatPadding="true" />

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

0 个答案:

没有答案