Закрыть выдвижную панель Android (библиотека Умано) на открытом ящике

Я реализовал скользящую панель, предоставленную библиотекой Umano, в своем приложении для Android. Я использовал свой макет ящика внутри выдвижной панели, как это

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);

не работает.


person CraZyDroiD    schedule 05.06.2015    source источник


Ответы (1)


Вы когда-нибудь видели, как он рухнул? Попробуйте поменять местами DrawerLayout и SlidingUpPanel, т.е. поставить второй на первый.

person khusrav    schedule 24.07.2015