Android Design Support控件之DrawerLayout简单使用
DrawerLayout能够让我们在项目中非常方便地实现側滑菜单效果。如今主流的应用如QQ等都
採用的这样的效果。
这两天也是在学习Android Design Support的相关知识。网上有关这方面的文章介绍非常多。可是为了方便以后使用,还是把学习的知识做个简单记录。这次的代码也是在上一篇博客Android Design Support控件介绍之TabLayout的基础上加入的布局和代码。
主界面布局:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_view"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.NavigationView
android:id="@+id/navigation_view"
android:layout_width="200dp"
android:layout_height="match_parent"
android:layout_gravity="left"
android:fitsSystemWindows="true"
app:headerLayout="@layout/content_main"><!--content_main与上篇文章中一样-->
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>
側滑菜单左側的布局
<?xml version="1.0" encoding="utf-8"?
>
<LinearLayout 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:orientation="vertical"
android:padding="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:text="菜单ONE" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="菜单TWO" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="菜单THREE" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="菜单FOUR" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="菜单FIVE" />
</LinearLayout>
Fragment界面布局
<?
xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical"
android:padding="10dp">
<TextView
android:id="@+id/content_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:text="菜单ONE" />
</LinearLayout>
主界面代码,TestAdapter 及TestFragment代码也同上一篇文章一样。
public class MainActivity extends FragmentActivity {
//便捷实现标签显示
private TabLayout tab_layout;
private ViewPager viewpager;
private TestAdapter mAdapter;
private List<Fragment> fragments;
private List<String> titles;
private DrawerLayout drawer_view;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.drawer_layout);
initViews();
initViewPages();
}
private void initViewPages() {
fragments = new ArrayList<>();
titles = new ArrayList<>();
for (int i = 0; i < 4; i++) {
String title="TAB" + i;
titles.add(title);
tab_layout.addTab(tab_layout.newTab().setText(title));//加入Tab标题
Fragment fragment = new TestFragment();
Bundle bundle = new Bundle();
bundle.putString("content", "这是第" + i + "个Fragment页面");
fragment.setArguments(bundle);
fragments.add(fragment);
}
mAdapter = new TestAdapter(this.getSupportFragmentManager(), titles, fragments);
viewpager.setAdapter(mAdapter);
tab_layout.setupWithViewPager(viewpager);
tab_layout.setTabsFromPagerAdapter(mAdapter);
}
private void initViews() {
tab_layout = (TabLayout) findViewById(R.id.tab_layout);
viewpager = (ViewPager) findViewById(R.id.viewpager);
drawer_view=(DrawerLayout)findViewById(R.id.drawer_view);
drawer_view.closeDrawer(GravityCompat.START);
}
}
效果图:
Android Design Support控件之DrawerLayout简单使用的更多相关文章
- android design 新控件
转载请标明出处: http://blog.csdn.net/forezp/article/details/51873137 本文出自方志朋的博客 最近在研究android 开发的新控件,包括drawe ...
- Android Design Support Library介绍之:环境搭建
在2015年的GoogleIO大会上.具体的Material Design设计规范出炉了.全新的Android Design Support Library 格.更让人开心的是,这些很酷的风格能够通过 ...
- Android Design Support Library 中控件的使用简单介绍(一)
Android Design Support Library 中控件的使用简单介绍(一) 介绍 在这个 Lib 中主要包含了 8 个新的 material design 组件!最低支持 Android ...
- MaterialEditText——Android Material Design EditText控件
MaterialEditText是Android Material Design EditText控件.可以定制浮动标签.主要颜色.默认的错误颜色等. 随着 Material Design 的到来, ...
- Android基本控件Spinner的简单使用【转】
Android基本控件Spinner的简单使用 感谢大佬:https://blog.csdn.net/bingocoder/article/details/80469939 学习过了Textview, ...
- Android Design Support Library使用详解
Android Design Support Library使用详解 Google在2015的IO大会上,给我们带来了更加详细的Material Design设计规范,同时,也给我们带来了全新的And ...
- 一个Activity掌握Design新控件 (转)
原文地址:http://blog.csdn.net/lavor_zl/article/details/51295364 谷歌在推出Android5.0的同时推出了全新的设计Material Desig ...
- 【转】【翻】Android Design Support Library 的 代码实验——几行代码,让你的 APP 变得花俏
转自:http://mrfufufu.github.io/android/2015/07/01/Codelab_Android_Design_Support_Library.html [翻]Andro ...
- 【转】Android M新控件之AppBarLayout,NavigationView,CoordinatorLayout,CollapsingToolbarLayout的使用
Android M新控件之AppBarLayout,NavigationView,CoordinatorLayout,CollapsingToolbarLayout的使用 分类: Android UI ...
随机推荐
- sass07 函数
scsss @function double($width){ //自定义函数u @return $width * 2; } @function double($width){ //自定义函数u @i ...
- 安卓开发,adb shell 调试sqlite3数据库
安卓开发,adb shell 调试sqlite3数据库 在安卓中创建了sqlite3数据库,想要调试怎么办? 通过adb shell来进行查看. 第一步,将adb加入到系统变量中. 这样就可以在命令行 ...
- 【转】android新组件RecyclerView使用介绍和进阶使用,替用Gallery
简介: RecyclerView是support-v7包中的新组件,是一个强大的滑动组件,与经典的ListView相比,同样拥有item回收复用的功能,但是直接把viewholder的实现封装起来,用 ...
- POJ 2449 第k短路 Dijkstra+A*
这道题我拖了半年,,,终于写出来了 思路: 先反向建边 从终点做一次最短路 ->这是估价函数h(x) 再正常建边,从起点搜一遍 (priority_queue(h(x)+g(x))) g(x)是 ...
- Wordpress 问题
迁移乱码 最近在做 wordpress 迁移,数据导入到服务器后,前后台都是乱码, phpMyAdmin 里的表数据就出现了乱码. 如果您也遇到和我一样的情况,本地使用 phpMyAdmin 导出 s ...
- 空宏-标C中空宏的妙用
空宏的作用: 1)编译指示: 2)方便阅读: 定义宏,并在预处理过程中将其替换为空字符串(即删除) 偶然的机会,看到了下面的C代码:ISC_PLATFORM_NORETURN_PRE static v ...
- node使用express命令报错找不到ejs的解决方法
首先确定已经全局安装过好几遍express和express-generator,但一使用express命令直接报找不到ejs模块,全局和本地安装ejs都没用,nodemon模块报同样错误,找不到deb ...
- XAMPP添加多个站点之httpd-vhosts.conf 设置
1.在xampp\apache\conf\httpd.conf设置路径DocumentRoot和Directory 必须与xampp\apache\conf\extra\httpd-vhosts.co ...
- Win10 + YOLOv3 环境配置,编译,实现目标检测----How to compile YOLOv3 on Windows
其他比较好的参考链接: 环境配置: 环境配置的最终图片列表:https://blog.csdn.net/shanglianlm/article/details/80322718 视频讲解YOLOv1: ...
- P1872 回文串计数(回文树)
题目描述 小a虽然是一名理科生,但他常常称自己是一名真正的文科生.不知为何,他对于背诵总有一种莫名其妙的热爱,这也促使他走向了以记忆量大而闻名的生物竞赛.然而,他很快发现这并不能满足他热爱背诵的心,但 ...