安卓NavigationView使用方法(1)

在这个页面中直接找到design这个依赖,点击后再点击这两个窗口上的OK按钮,等待编译完成就完成导入了!

(可能版本不一样,导入即可)

13.1.5 介绍NavigationView


Google在5.0之后推出的NavitationView,所有的布局控件放在DrawerLayout中来使用,NavigationView的作用就像这样,实现侧拉效果。和DrawerLayout效果几分差异,QQ从左至右从边滑动的侧拉效果。上半部分图片背景,圆形头像,下面每一个都是导航菜单现在就来实现一下它(虽然是Iphone图,但是没关系了,就是这个道理)。


布局文件、标签属性


敲出最简单的布局,实现最简单的效果

<?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”

xmlns:tools=“http://schemas.android.com/tools”

android:layout_width=“match_parent”

android:layout_height=“match_parent”

tools:context=“.MainActivity”>

<LinearLayout

android:background=“#4d7aed”

android:layout_width=“match_parent”

android:layout_height=“match_parent”>

<TextView

android:gravity=“center”

android:textSize=“18sp”

android:text=“这里是一个主页面”

android:layout_width=“match_parent”

android:layout_height=“match_parent” />

<android.support.design.widget.NavigationView

android:layout_gravity=“left”

android:background=“#ffffff”

android:layout_width=“match_parent”

android:layout_height=“match_parent”>

</android.support.design.widget.NavigationView>

</android.support.v4.widget.DrawerLayout>

将所有布局控件放下DrawerLayout 中,NavigationView加上属性android:layout_gravity="left"实现左侧滑!


如果加一个头布局文件,姐可以侧拉出这样的效果布局代码如下

主布局文件activity_main.xml:

<?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”

xmlns:tools=“http://schemas.android.com/tools”

android:layout_width=“match_parent”

android:layout_height=“match_parent”

tools:context=“.MainActivity”>

<LinearLayout

android:layout_width=“match_parent”

android:layout_height=“match_parent”

android:background=“#4d7aed”>

<TextView

android:layout_width=“match_parent”

android:layout_height=“match_parent”

android:gravity=“center”

android:text=“这里是一个主页面”

android:textSize=“18sp” />

<android.support.design.widget.NavigationView

app:headerLayout=“@layout/layout”

android:layout_width=“450dp”

android:layout_height=“match_parent”

android:layout_gravity=“start”

android:background=“#ffffff”>

</android.support.design.widget.NavigationView>

</android.support.v4.widget.DrawerLayout>

头布局文件layout.xml

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android=“http://schemas.android.com/apk/res/android”

android:layout_width=“match_parent”

android:layout_height=“260dp”

android:orientation=“vertical”>

<ImageView

android:layout_width=“match_parent”

android:layout_height=“230dp”

android:background=“@mipmap/kb” />

<TextView

android:layout_width=“match_parent”

android:layout_height=“30dp”

android:background=“#63a6e9”

android:gravity=“center”

android:text=“《魁拔》”

android:textColor=“#fff”

android:textSize=“18sp” />


之后加上menu就可以实现这样的效果了(虽然丑了,但是还是可以实现,要求美观就细扣)

创建的menu应该在这里

menu.xml

<?xml version="1.0" encoding="utf-8"?>

<item

android:id=“@+id/item1”

android:title=“功能列表1”>

<item

android:id=“@+id/item2”

android:title=“功能列表2”>

<item

android:id=“@+id/item3”

android:title=“功能列表3”>

<item

android:id=“@+id/item4”

android:title=“功能列表4”>

<item

android:id=“@+id/item5”

android:title=“功能列表5”>

还可以在每个item加上  android:icon=“”  ,为这个item设置上图标

布局文件

<?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”

xmlns:tools=“http://schemas.android.com/tools”

android:layout_width=“match_parent”

android:layout_height=“match_parent”

tools:context=“.MainActivity”>

<LinearLayout

android:layout_width=“match_parent”

android:layout_height=“match_parent”

android:background=“#4d7aed”>

<TextView

android:layout_width=“match_parent”

android:layout_height=“match_parent”

android:gravity=“center”

最后

自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。

深知大多数初中级Android工程师,想要提升技能,往往是自己摸索成长,自己不成体系的自学效果低效漫长且无助

因此我收集整理了一份《2024年Android移动开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Android开发知识点!不论你是刚入门Android开发的新手,还是希望在技术上不断提升的资深开发者,这些资料都将为你打开新的学习之门

如果你觉得这些内容对你有帮助,需要这份全套学习资料的朋友可以戳我获取!!

由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!
PDCQJSU-1715895384064)]

[外链图片转存中…(img-84F6R6gh-1715895384064)]

[外链图片转存中…(img-0bkjgEUs-1715895384065)]

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Android开发知识点!不论你是刚入门Android开发的新手,还是希望在技术上不断提升的资深开发者,这些资料都将为你打开新的学习之门

如果你觉得这些内容对你有帮助,需要这份全套学习资料的朋友可以戳我获取!!

由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!

  • 15
    点赞
  • 30
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值