在抽屉打开时关闭android向上滑动面板(Umano Library)

时间:2015-06-05 11:14:51

标签: android layout navigation-drawer slidingpanelayout

我在我的Android应用程序中实现了Umano库提供的向上滑动面板。我在这个

中使用了我的抽屉布局

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/mainLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">


    <include
        android:id="@+id/toolbar_actionbar"
        layout="@layout/toolbar_default"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/fmYellow" />


    <com.sothree.slidinguppanel.SlidingUpPanelLayout xmlns:sothree="http://schemas.android.com/apk/res-auto"
        android:id="@+id/sliding_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/toolbar_actionbar"
        android:gravity="bottom"
        sothree:umanoPanelHeight="60dp"
        sothree:umanoShadowHeight="4dp">


        <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/drawer"
            android:layout_width="match_parent"
            android:layout_height="match_parent">


            <FrameLayout
                android:id="@+id/container"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:clickable="true" />

            <!-- android:layout_marginTop="?android:attr/actionBarSize"-->
            <fragment
                android:id="@+id/fragment_drawer"
                android:name="com.fm.etunes.phone.view.NavigationDrawerFragment"
                android:layout_width="@dimen/navigation_drawer_width"
                android:layout_height="match_parent"
                android:layout_gravity="start"
                app:layout="@layout/fragment_navigation_drawer"
                tools:layout="@layout/fragment_navigation_drawer" />

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


        <LinearLayout
            android:id="@+id/blurbackground"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#464646"
            android:orientation="vertical">

            <LinearLayout
                android:id="@+id/bottomBar"
                android:layout_width="match_parent"
                android:layout_height="60dp"
                android:orientation="horizontal">

                <ImageView
                    android:id="@+id/song_image"
                    android:layout_width="50dp"
                    android:layout_height="50dp"
                    android:padding="5dp"
                    android:src="@drawable/ic_launcher1" />


                <LinearLayout
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:orientation="vertical">

                    <TextView
                        android:id="@+id/song_title"
                        android:layout_width="match_parent"
                        android:layout_height="0dp"
                        android:layout_weight="1"
                        android:text="Etunes"
                        android:textColor="@color/player_footer_text_color"
                        android:textStyle="bold" />

                    <TextView
                        android:id="@+id/artist_name"
                        android:layout_width="match_parent"
                        android:layout_height="0dp"
                        android:layout_weight="1"
                        android:textSize="13dp"
                        android:text="Etunes"
                        android:singleLine="true"
                        android:textColor="@color/player_footer_text_color" />

                </LinearLayout>
     </com.sothree.slidinguppanel.SlidingUpPanelLayout>
</RelativeLayout>

它完全像它应该的那样工作。但我遇到的问题是我想在抽屉打开时关闭滑动面板。我已经使用了这段代码,却无法让它工作。如何在抽屉打开时关闭滑动面板。

@Override
    public boolean onCreateOptionsMenu(Menu menu) {
        if (!mNavigationDrawerFragment.isDrawerOpen()) {


            // Only show items in the action bar relevant to this screen
            // if the drawer is not showing. Otherwise, let the drawer
            // decide what to show in the action bar.
            getMenuInflater().inflate(R.menu.main, menu);
            return true;

        } else {

            Toast.makeText(activity,"drawer open",Toast.LENGTH_LONG).show();
            slidingUpPanelLayout.setPanelState(SlidingUpPanelLayout.PanelState.COLLAPSED);

        }
        return super.onCreateOptionsMenu(menu);
    }
PS:我得到吐司说抽屉正在打开。但似乎

slidingUpPanelLayout.setPanelState(SlidingUpPanelLayout.PanelState.COLLAPSED);

无效。

1 个答案:

答案 0 :(得分:0)

你见过它崩溃了吗?尝试调整DrawerLayout和SlidingUpPanel的位置,即将第二个放入第一个位置。