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 ...
随机推荐
- Codeforces 559B Equivalent Strings 等价串
题意:给定两个等长串a,b.推断是否等价.等价的含义为:若长度为奇数,则必须是同样串.若长度是偶数,则将两串都均分成长度为原串一半的两个子串al,ar和bl,br,当中al和bl等价且ar和br等价, ...
- nj08---process、console
概念:所有属性都可以在程序的任何地方访问,即全局变量.在JavaScript中,通常window是全局对象,而Node.js的全局对象是global,所有全局变量都是global对象的属性,如:con ...
- 13.MongoDB 连接命令格式
转自:https://www.linuxidc.com/Linux/2016-03/129456.htm 使用用户 admin 使用密码 123456 连接到本地的 MongoDB 服务上.输出结果如 ...
- Random words
To choose a random word from the histogram, the simplest algorithm is to build a list with multiple ...
- 鼠标滑过,解决ul下 li下a的背景与父级Li不同宽的问题
我们在写导航或者页面有超链接的地方,有一些是需要超链接的背景和Li的宽度一样的.但是,却没有达到这种效果?为什么? 我们做的效果图:如下 期望的效果:如下 出现这样的原因:由于a是个行内元素,它没有宽 ...
- PostgreSQL Replication之第八章 与pgbouncer一起工作(3)
8.3 配置您的第一个pgbouncer设置 一旦我们已经完成了pbouncer的编译与安装,我们可以容易地启动它.要做到这一点,我们已经在一个本地实例(p0和p1) 建立了两个数据库.在本例中,执行 ...
- vue 中使用querySelect 封装的万能选择器
function query (el) { if (typeof el === 'string') { var selector = el; el = document.querySelector(e ...
- win环境操作mysql
第一步:登录数据库 第二步:查看数据库 第三步:进入数据库 第四步:创建表 第五步:删除数据库 第六步:进入数据库查看表状态
- 我的 Linux 主目录中的隐藏文件是干什么用的?
作者: Alexander Fox 译者: LCTT MjSeven 在 Linux 系统中,你可能会在主目录中存储了大量文件和文件夹.但在这些文件之外,你知道你的主目录还附带了很多隐藏的文件和文件夹 ...
- 洛谷2850 【Usaco2006 Dec】虫洞Wormholes SPFA
问题描述 John在他的农场中闲逛时发现了许多虫洞.虫洞可以看作一条十分奇特的有向边,并可以使你返回到过去的一个时刻(相对你进入虫洞之前).John的每个农场有M条小路(无向边)连接着N (从1..N ...