DrawerLayout学习,抽屉效果

第一节:

注意事项

*主视图一定要是DrawerLayout的第一子视图

*主视图宽度和高度匹配父视图,因为当你显示主视图时,要铺满整个屏幕,用户体验度较高

*必须显示指定的抽屉视图的android:layout_gravity属性

first:android:layout_gravity="start",左-->右滑出菜单

second:android:layout_gravity="end",右-->左滑出菜单

不推荐left,right

*抽屉视图的宽度以dp为单位,最佳不要超过父视图的2/3

效果图展示:

 

代码展示:

activity_main.xml

 1 <android.support.v4.widget.DrawerLayout
 2     xmlns:android="http://schemas.android.com/apk/res/android"
 3     android:id="@+id/drawer_layout"
 4     android:layout_width="match_parent"
 5     android:layout_height="match_parent">
 6     
 7     <!-- the main content view -->
 8     
 9     <FrameLayout 
10         android:id="@+id/content_frame"
11         android:layout_width="match_parent"
12         android:layout_height="match_parent">
13         
14     </FrameLayout>
15     
16     <!-- the navigation view -->
17     <!-- start left->right -->
18     <ListView 
19         android:id="@+id/left_drawer"
20         android:layout_width="240dp"
21         android:layout_height="match_parent"
22         android:layout_gravity="start"
23         android:background="@drawable/listview_table"
24         android:choiceMode="singleChoice"
25         android:divider="@android:color/transparent"
26         android:dividerHeight="0dp">
27         
28     </ListView>
29 </android.support.v4.widget.DrawerLayout>

 

MainActivity.java

 1 import android.app.Activity;
 2 import android.os.Bundle;
 3 
 4 
 5 public class MainActivity extends Activity {
 6 
 7     @Override
 8     protected void onCreate(Bundle savedInstanceState) {
 9         super.onCreate(savedInstanceState);
10         setContentView(R.layout.activity_main);
11     }
12 
13  
14 }

 

感受:难点在于抽屉视图的理解和使用规则

 

posted on 2016-03-12 14:10  不二家的瓶子  阅读(557)  评论(0编辑  收藏  举报

导航