1、main_layout.xml

 <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_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"> <include layout="@layout/activity_main"/>
<!--
android:fitsSystemWindows="true|false":适合系统窗口
-->
<android.support.design.widget.NavigationView
android:id="@+id/navigetion_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="left"
android:fitsSystemWindows="true"
app:headerLayout="@layout/head_view"
app:menu="@menu/menu_main">
</android.support.design.widget.NavigationView> </android.support.v4.widget.DrawerLayout>

2、@layout/head_view  侧滑布局文件

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher"/>
</LinearLayout>

3、MainActivity.java

 package com.example.com.designdemo;

 import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import java.util.ArrayList;
import java.util.List; public class MainActivity extends AppCompatActivity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_layout); TabLayout tabs = (TabLayout) this.findViewById(R.id.tabs); List<String> titles = new ArrayList<String>();
List<Fragment> fragments = new ArrayList<Fragment>();
for (int i=0; i<10; i++) {
String title = "Tab"+ (i+1);
tabs.addTab(tabs.newTab().setText(title));
titles.add(title); Fragment fragment = new TestOneFragment(title);
fragments.add(fragment);
} ViewPager viewpager = (ViewPager) this.findViewById(R.id.viewpager);
TestOneAdapter mAdapter = new TestOneAdapter(getSupportFragmentManager(), titles, fragments);
viewpager.setAdapter(mAdapter);
tabs.setupWithViewPager(viewpager);
tabs.setTabsFromPagerAdapter(mAdapter); // 控制侧滑菜单的显示和隐藏
//DrawerLayout drawer_layout = (DrawerLayout) this.findViewById(R.id.drawer_layout);
//drawer_layout.closeDrawer();

} }

62、常规控件(5)Navigation View –美观的侧滑视图的更多相关文章

  1. Android 控件架构及View、ViewGroup的测量

    附录:示例代码地址 控件在Android开发的过程中是必不可少的,无论是我们在使用系统控件还是自定义的控件.下面我们将讲解一下Android的控件架构,以及如何实现自定义控件. 1.Android控件 ...

  2. 61、常规控件(4)TabLayout-便捷实现标签

    <android.support.design.widget.TabLayout android:id="@+id/tabs" android:layout_width=&q ...

  3. Pyqt5——表格中隐藏的控件(Model/View/Delegate)

    需求:在TableView表格中点击单元格可以实现编辑功能.性别由LineEdite控件编辑,年龄由spinBox控件编辑. 实现:(1)使用Qt的model-view模式生成表格视图.    (2) ...

  4. Android控件postDelayed用法,View自带的定时器

    有一个需求是这样的,点击加关注按钮后,执行关注操作,成功后按钮文字变为“已关注”,保持3秒,三秒后按钮文字便问“取消关注”,点击后执行取消关注的操作 源码: public boolean postDe ...

  5. 60、常规控件(3)Snackbar-可操作的提示框,Toast升级版

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app=&quo ...

  6. QT常规控件操作备忘

    QLabel设置边框和颜色: label->setFrameShape (QFrame::Box); label->setStyleSheet("border: 1px soli ...

  7. mvc 用户控件 ascx 获取 View 页面的值

    <%Html.RenderAction("AscxSideNav", "UI", new {itemName=ViewData["ItemNam ...

  8. SectionIndexer 利用系统的控件,制作比较美观的侧栏索引控件

    如上图所示,右侧的索引是系统提供的,具体使用方法,请搜索: SectionIndexer 相关的资料进行开发.

  9. html学习第一讲(内容html常规控件的的使用)

    <html> <head> <title> 这是网页的标题</title> </head> <body> <h2>& ...

随机推荐

  1. shell脚本中执行mysql 语句,去除warning using a password on the command line interface can be insecure信息

    方法二:使用mysql参数的方法 mysql -u$user -p$pass -D $db -e "select host from user;"当然,可以通过将传参的方式来传递 ...

  2. MBProgressHUD 设置透明背景

    MBProgressHUD 默认使用MBProgressHUDBackgroundStyleBlur 类型 MBProgressHUDBackgroundStyleBlur使用了毛玻璃效果 ,我们要把 ...

  3. PadLeft函数

    string num=12 num.PadLeft(4, '0'); //结果为为 '0012' 看字符串长度是否满足4位,不满足则在字符串左边以"0"补足

  4. 点滴积累【JS】---JS小功能(JS实现侧悬浮浮动)

    效果: 思路: 首先,加载onscroll控制滚动条.然后写缓存运动的方法,缓冲运动的方法是先计算出DIV缓冲的速度,并且将其取整,再进行运动判断什么时候到达终点.最后将其参数返回.再在onscrol ...

  5. source insight 支持verilog 及使用技巧

    安装 1.首先到官网下载clf文件 http://www.sourceinsight.com/public/languages/ 2.配置source insight 以前有的先删除 Options ...

  6. 代码覆盖率?coverage

    http://www.infoq.com/cn/articles/test-coverage-rate-role 代码覆盖率?coverage   http://www.cnblogs.com/cod ...

  7. [svc]msmtp+mutt发附件,发邮件给多个人

    环境:centos6.7 x86-64 内网有web服务器(curl可展示目录) #预安装软件 yum install lrzsz ntpdate sysstat dos2unix wget teln ...

  8. redis命令_ZREM

    ZREM key member [member ...] 移除有序集 key 中的一个或多个成员,不存在的成员将被忽略. 当 key 存在但不是有序集类型时,返回一个错误. 在 Redis 2.4 版 ...

  9. HTTP认证机制

    HTTP的询问/应答机制 如下图: 一个实例的图: 1.客户端请求资源 2.服务器对用户进行询问,在WWW-Authenticate首部中指明在哪里,如何进行认证 3.客户端会在Authenticat ...

  10. Ecmall二次开发-增删改查操作

    Ecmall二次开发-增删改查操作 Model目录includes/models 自己添加需要的model class OrdercomplainModel extends BaseModel //类 ...