2017-09-22 3 views
1

私は最初に引き出しレイアウトで星が付いているアクティビティを持っていたいと思います。私は単純に入れてみました。アクティビティの開始時にdrawerLayoutを開くにはどうすればよいですか?

mDrawerLayout.openDrawer(gravity.END()); 

私のコードのいろいろなところにありますが、引き出しを閉じて再び開くまで、アイテムはクローキングできなくなります。

誰もがこれに運があったのですか?この機能を追加するのは、主にユーザーエクスペリエンス上の理由によるものです。

マイ引き出しレイアウトにはリストビューがあり、クリックするとそのアクティビティでRecyclerViewが変更されます。

これは、必要な人のための私のXMLファイルです。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="@color/colorPrimary" 
android:orientation="vertical"> 


<!--android:elevation="4dp"--> 
<!-- The drawer is given a fixed width in dp and extends the full height of 
    the container. --> 

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

    <!-- The navigation drawer --> 
    <ListView 
     android:id="@+id/right_drawer" 
     android:layout_width="240dp" 
     android:layout_height="match_parent" 
     android:layout_gravity="start" 
     android:alpha="0.8" 
     android:background="@color/colorPrimary" 
     android:choiceMode="singleChoice" 
     android:divider="@android:color/transparent" 
     android:dividerHeight="0dp" /> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/my_toolbar2" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:alpha="1" 
      android:background="?attr/colorAccent" 
      android:theme="@style/ThemeOverlay.AppCompat.ActionBar" 
      app:popupTheme="@style/ThemeOverlay.AppCompat" /> 

    <android.support.design.widget.CoordinatorLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" 
     android:padding="10dp" 
     android:layout_below="@+id/my_toolbar2"> 



     <android.support.v7.widget.RecyclerView 
      android:id="@+id/listview2" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_marginBottom="5dp" 
      android:layout_marginLeft="5dp" 
      android:layout_marginRight="5dp" 
      android:background="@color/colorPrimary" 
      android:dividerHeight="8dp" /> 

     <android.support.design.widget.FloatingActionButton 
      android:id="@+id/fab" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center_vertical|center_horizontal" 
      android:src="@drawable/ic_add_circle_outline_white_24dp" 
      android:visibility="visible" 
      app:elevation="24dp" 
      app:fabSize="auto" 
      app:layout_anchor="@+id/listview2" 
      app:layout_anchorGravity="bottom|end" 
      app:rippleColor="#FFF" /> 


    </android.support.design.widget.CoordinatorLayout> 
    </RelativeLayout> 
</android.support.v4.widget.DrawerLayout> 

答えて

1

ActivityのごonCreate(Bundle savedInstanceState)で、次のように行うようにしてください:

mDrawerLayout = findViewById(R.id.drawer_layout); 
    mDrawerLayout.postDelayed(new Runnable() { 
     @Override 
     public void run() { 
      if (mDrawerLayout != null) { 
       mDrawerLayout.openDrawer(Gravity.LEFT); 
      } 
     } 
    }, 200); 
+0

今ユーザーが、むしろそれだけで開いているよりも、引き出し開口部のアニメーションを見ることができるので、これが大きすぎますそれが始まるとき。 –

関連する問題