zoukankan      html  css  js  c++  java
  • 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 }

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

  • 相关阅读:
    一本通1268 完全背包问题
    一本通1267 01背包
    合并石子1,2
    求最长不下降子序列++
    数字金字塔升级版
    一本通1354 括弧匹配检验
    一本通1353表达式括号匹配
    一本通1357车厢调度
    Centos查看端口占用情况和开启端口命令
    centos后台运行python程序
  • 原文地址:https://www.cnblogs.com/mbp-study/p/5268594.html
Copyright © 2011-2022 走看看