【笔记】android滑动菜单
来源:互联网 发布:淘宝u站九块邮 编辑:程序博客网 时间:2024/06/08 04:09
万恶的产品总是没事找事,侧滑菜单这种东西感觉都已经过时了,却还要用。实在没办法只能找了下资料,这里自己把认为实现起来比较容易的方法做下记录。
DrawerLayout + NavigationView
布局
<?xml version="1.0" encoding="utf-8"?><android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/dl" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.sjl.slidemenu.NavigationViewActivity" tools:openDrawer="start"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <Button android:id="@+id/btnSlide" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="滑动" /> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/tvSelect"/> </LinearLayout> <android.support.design.widget.NavigationView android:id="@+id/navView" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_gravity="start" android:fitsSystemWindows="true" app:headerLayout="@layout/navigation_view_header" app:menu="@menu/navigation_view_menu" /></android.support.v4.widget.DrawerLayout>
初始化滑动菜单
/** * 初始化侧滑菜单 */ private void initSlideMenu() { //获取NavigationView头部 View header = navView.getHeaderView(0); ivHeaderImg = (ImageView) header.findViewById(R.id.ivHeaderImg); ivHeaderImg.setOnClickListener(this); tvHeaderTitle = (TextView) header.findViewById(R.id.tvHeaderTitle); tvHeaderTitle.setOnClickListener(this); navView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() { @Override public boolean onNavigationItemSelected(MenuItem item) { //菜单选中 item.setChecked(true); //关闭侧滑 dl.closeDrawers(); tvSelect.setText(item.getTitle()); return true; } }); }
DrawerLayout + ListView
布局
<?xml version="1.0" encoding="utf-8"?><android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/dl" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.sjl.slidemenu.ListMenuActivity"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <Button android:id="@+id/btnSlide" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="滑动" /> <TextView android:id="@+id/tvSelect" android:layout_width="match_parent" android:layout_height="wrap_content" /> </LinearLayout> <ListView android:id="@+id/lvMenu" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="start" android:background="#ffffffff"></ListView></android.support.v4.widget.DrawerLayout>
/** * 初始化侧滑菜单 */ private void initSlideMenu() { View header = LayoutInflater.from(this).inflate(R.layout.navigation_view_header,null); //添加不可被选择的头部 lvMenu.addHeaderView(header,null,false); ivHeaderImg = (ImageView) header.findViewById(R.id.ivHeaderImg); ivHeaderImg.setOnClickListener(this); tvHeaderTitle = (TextView) header.findViewById(R.id.tvHeaderTitle); tvHeaderTitle.setOnClickListener(this); adapter = new ArrayAdapter(this,android.R.layout.simple_list_item_1,items); lvMenu.setAdapter(adapter); lvMenu.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { tvSelect.setText(items[position-1]); dl.closeDrawers(); } }); }
源码
0 0
- 【笔记】android滑动菜单
- Android滑动菜单
- Android 圆形滑动菜单
- Android滑动菜单
- Android滑动菜单
- Android滑动菜单
- Android滑动菜单
- Android双向滑动菜单
- android滑动菜单SlidingMenu
- android滑动菜单demo
- android双向滑动菜单
- Android侧边滑动菜单
- Android菜单滑动
- Android学习笔记 - 滑动菜单SlidingMenu的实现
- Android双向滑动菜单特效
- android选项卡,菜单滑动
- android 滑动菜单SlidingMenu实现
- Android滑动菜单特效实现
- Java——线程通信
- 手动创建Maven项目
- 什么是【真正的】兴趣爱好?以及它有啥好处?
- 蓝桥杯第四届 第39级台阶
- bootstrap实现图片自动轮播
- 【笔记】android滑动菜单
- c# windows编程基础
- Python学习笔记:讲两个list合并成字典dict
- 机器学习面试准备
- AndroidHttpClient详解
- 关于SOA的一些概念问题
- spfa 汇率转换
- JeeWx捷微3.0多触点版本发布,支持微信公众号,微信企业号,支付窗——喜迎双“旦”
- strlen().printf()和scanf()函数