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 ...
随机推荐
- django uWSGI nginx搭建一个web服务器 确定可用
网上的找了很多篇 不知道为什么不行,于是自己搭建了一个可用的Web 大家可按步骤尝试 总结下基于uwsgi+Nginx下django项目生产环境的部署 准备条件: .确保有一个能够用runserver ...
- Spring 4 CustomEditorConfigurer Example--转
原文地址:http://howtodoinjava.com/spring/spring-core/registering-built-in-property-editors-in-spring-4-c ...
- Wordpress 问题
迁移乱码 最近在做 wordpress 迁移,数据导入到服务器后,前后台都是乱码, phpMyAdmin 里的表数据就出现了乱码. 如果您也遇到和我一样的情况,本地使用 phpMyAdmin 导出 s ...
- HDU 2515 Yanghee 的算术【找规律】
题意:中文的题目 找规律可以发现 sum[1]=a[1]+a[2] sum[2]=a[1]+a[3] sum[n]=a[2]+a[3] 解出a[1],就可以求出其他的了 #include<ios ...
- codeforces 527 C Glass Carving
Glass Carving time limit per test 2 seconds Leonid wants to become a glass carver (the person who cr ...
- UVALive 6486 Skyscrapers 简单动态规划
题意: 有N个格子排成一排,在每个格子里填上1到N的数(每个只能填一次),分别代表每个格子的高度.现在给你两个数left和right,分别表示从左往右看,和从右往左看,能看到的格子数.问有多少种情况. ...
- Unity shader 代码高亮+提示
Shader Unity Support This is Unity CG Shaders Support. It has code completion support and uses C/C++ ...
- [Recompose] Pass a React Prop to a Stream in RxJS
When you declare your Component and Props in JSX, you can pass those props along to your RxJS stream ...
- HackingTeam重磅炸弹: 估值超1000万美金带有军火交易性质的木马病毒以及远控源代码泄露
[简单介绍] 经常使用网名: 猪头三 出生日期: 1981.XX.XX 个人站点: http://www.x86asm.com QQ交流: 643439947 编程生涯: 2001年~至今[共14年] ...
- Android程序猿自己动手制作.9.png图片
1:怎样制作9.png图片素材: 打开SDK工具文件夹下: draw9patch.zip 解压执行draw9patch.bat.有的直接搜索会有:draw9patch.bat. 双击执行后,例如以下 ...