Android DrawerLayout 高仿QQ5

android:layout_alignParentRight=“true”

android:background=“@drawable/youce”

android:onClick=“OpenRightMenu” />

<fragment

android:id=“@+id/id_left_menu”

android:name=“com.zhy.demo_zhy_17_drawerlayout.MenuLeftFragment”

android:layout_width=“200dp”

android:layout_height=“match_parent”

android:layout_gravity=“left”

android:tag=“LEFT” />

<fragment

android:id=“@+id/id_right_menu”

android:name=“com.zhy.demo_zhy_17_drawerlayout.MenuRightFragment”

android:layout_width=“100dp”

android:layout_height=“match_parent”

android:layout_gravity=“right”

android:tag=“RIGHT” />

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

这里我们的主内容区域为RelativeLayout

菜单用的两个Fragment,左侧为200dp,右侧为100dp;

好了,看了我们的布局文件,接下来看下我们的详细代码。

3、代码是最好的老师

==========

1、MenuLeftFragment


package com.zhy.demo_zhy_17_drawerlayout;

import android.os.Bundle;

import android.support.v4.app.Fragment;

import android.view.LayoutInflater;

import android.view.View;

import android.view.ViewGroup;

public class MenuLeftFragment extends Fragment

{

@Override

public View onCreateView(LayoutInflater inflater, ViewGroup container,

Bundle savedInstanceState)

{

return inflater.inflate(R.layout.layout_menu, container, false);

}

}

对应的布局文件:

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

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

android:layout_width=“match_parent”

android:layout_height=“match_parent”

android:background=“#00000000” >

<LinearLayout

android:layout_width=“match_parent”

android:layout_height=“wrap_content”

android:layout_centerVertical=“true”

android:orientation=“vertical” >

<RelativeLayout

android:layout_width=“match_parent”

android:layout_height=“wrap_content” >

<ImageView

android:id=“@+id/one”

android:layout_width=“50dp”

android:layout_height=“50dp”

android:layout_centerVertical=“true”

android:layout_marginLeft=“20dp”

android:layout_marginTop=“20dp”

android:src=“@drawable/img_1” />

<TextView

android:layout_width=“fill_parent”

android:layout_height=“wrap_content”

android:layout_centerVertical=“true”

android:layout_marginLeft=“20dp”

android:layout_toRightOf=“@id/one”

android:text=“第1个Item”

android:textColor=“#f0f0f0”

android:textSize=“20sp” />

<RelativeLayout

android:layout_width=“match_parent”

android:layout_height=“wrap_content” >

<ImageView

android:id=“@+id/two”

android:layout_width=“50dp”

android:layout_height=“50dp”

android:layout_centerVertical=“true”

android:layout_marginLeft=“20dp”

android:layout_marginTop=“20dp”

android:src=“@drawable/img_2” />

<TextView

android:layout_width=“fill_parent”

android:layout_height=“wrap_content”

android:layout_centerVertical=“true”

android:layout_marginLeft=“20dp”

android:layout_toRightOf=“@id/two”

android:text=“第2个Item”

android:textColor=“#f0f0f0”

android:textSize=“20sp” />

<RelativeLayout

android:layout_width=“match_parent”

android:layout_height=“wrap_content” >

<ImageView

android:id=“@+id/three”

android:layout_width=“50dp”

android:layout_height=“50dp”

android:layout_centerVertical=“true”

android:layout_marginLeft=“20dp”

android:layout_marginTop=“20dp”

android:src=“@drawable/img_3” />

<TextView

android:layout_width=“fill_parent”

android:layout_height=“wrap_content”

android:layout_centerVertical=“true”

android:layout_marginLeft=“20dp”

android:layout_toRightOf=“@id/three”

android:text=“第3个Item”

android:textColor=“#f0f0f0”

android:textSize=“20sp” />

<RelativeLayout

android:layout_width=“match_parent”

android:layout_height=“wrap_content” >

<ImageView

android:id=“@+id/four”

android:layout_width=“50dp”

android:layout_height=“50dp”

android:layout_centerVertical=“true”

android:layout_marginLeft=“20dp”

android:layout_marginTop=“20dp”

android:src=“@drawable/img_4” />

<TextView

android:layout_width=“fill_parent”

android:layout_height=“wrap_content”

android:layout_centerVertical=“true”

android:layout_marginLeft=“20dp”

android:layout_toRightOf=“@id/four”

android:text=“第4个Item”

android:textColor=“#f0f0f0”

android:textSize=“20sp” />

<RelativeLayout

android:layout_width=“match_parent”

android:layout_height=“wrap_content” >

<ImageView

android:id=“@+id/five”

android:layout_width=“50dp”

android:layout_height=“50dp”

android:layout_centerVertical=“true”

android:layout_marginLeft=“20dp”

android:layout_marginTop=“20dp”

android:src=“@drawable/img_5” />

<TextView

android:layout_width=“fill_parent”

android:layout_height=“wrap_content”

android:layout_centerVertical=“true”

android:layout_marginLeft=“20dp”

android:layout_toRightOf=“@id/five”

android:text=“第5个Item”

android:textColor=“#f0f0f0”

android:textSize=“20sp” />

其实就是堆出来的布局~~没撒意思~

2、MenuRightFragment


package com.zhy.demo_zhy_17_drawerlayout;

import android.os.Bundle;

import android.support.v4.app.Fragment;

import android.view.LayoutInflater;

import android.view.View;

import android.view.ViewGroup;

public class MenuRightFragment extends Fragment

{

@Override

public View onCreateView(LayoutInflater inflater, ViewGroup container,

Bundle savedInstanceState)

{

return inflater.inflate(R.layout.menu_layout_right, container, false);

}

}

对应布局文件:

<?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=“match_parent”

android:gravity=“center_vertical”

android:orientation=“vertical” >

<LinearLayout

android:layout_width=“match_parent”

android:layout_height=“wrap_content”

android:layout_centerVertical=“true”

android:layout_gravity=“center_vertical”

android:layout_marginBottom=“20dp”

android:orientation=“vertical” >

<ImageView

android:layout_width=“60dp”

android:layout_height=“60dp”

android:layout_gravity=“center”

android:src=“@drawable/wode” />

<TextView

android:layout_width=“fill_parent”

android:layout_height=“wrap_content”

android:gravity=“center”

android:text=“扫一扫”

android:textColor=“#ffffff” />

<LinearLayout

android:layout_width=“match_parent”

android:layout_height=“wrap_content”

android:layout_centerVertical=“true”

android:layout_gravity=“center_vertical”

android:layout_marginBottom=“20dp”

android:orientation=“vertical” >

<ImageView

android:layout_width=“60dp”

android:layout_height=“60dp”

android:layout_gravity=“center”

android:src=“@drawable/saoma” />

<TextView

android:layout_width=“fill_parent”

android:layout_height=“wrap_content”

android:gravity=“center”

android:text=“讨论组”

android:textColor=“#ffffff” />

<LinearLayout

android:layout_width=“match_parent”

android:layout_height=“wrap_content”

android:layout_centerVertical=“true”

android:layout_gravity=“center_vertical”

android:layout_marginBottom=“20dp”

android:orientation=“vertical” >

<ImageView

android:layout_width=“60dp”

android:layout_height=“60dp”

android:layout_gravity=“center”

android:src=“@drawable/wode” />

<TextView

android:layout_width=“fill_parent”

android:layout_height=“wrap_content”

android:gravity=“center”

android:text=“扫一扫”

android:textColor=“#ffffff” />

<LinearLayout

android:layout_width=“match_parent”

android:layout_height=“wrap_content”

android:layout_centerVertical=“true”

android:layout_gravity=“center_vertical”

android:layout_marginBottom=“20dp”

android:orientation=“vertical” >

<ImageView

android:layout_width=“60dp”

android:layout_height=“60dp”

android:layout_gravity=“center”

android:src=“@drawable/saoma” />

<TextView

android:layout_width=“fill_parent”

android:layout_height=“wrap_content”

android:gravity=“center”

android:text=“讨论组”

android:textColor=“#ffffff” />

依旧很简单,除了图标比较难找以外~~

3、MainActivity


MainActivity的布局文件已经贴过了~~

package com.zhy.demo_zhy_17_drawerlayout;

import android.os.Bundle;

import android.support.v4.app.FragmentActivity;

import android.support.v4.widget.DrawerLayout;

import android.support.v4.widget.DrawerLayout.DrawerListener;

import android.view.Gravity;

import android.view.View;

import android.view.Window;

import com.nineoldandroids.view.ViewHelper;

public class MainActivity extends FragmentActivity

{

private DrawerLayout mDrawerLayout;

@Override

protected void onCreate(Bundle savedInstanceState)

{

super.onCreate(savedInstanceState);

requestWindowFeature(Window.FEATURE_NO_TITLE);

setContentView(R.layout.activity_main);

initView();

initEvents();

}

public void OpenRightMenu(View view)

{

mDrawerLayout.openDrawer(Gravity.RIGHT);

mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED,

Gravity.RIGHT);

}

private void initEvents()

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

深知大多数初中级Android工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但对于培训机构动则近万的学费,着实压力不小。自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!

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

img

img

img

img

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Android开发知识点,真正体系化!

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

如果你觉得这些内容对你有帮助,可以扫码获取!!(备注:Android)

学习分享

在当下这个信息共享的时代,很多资源都可以在网络上找到,只取决于你愿不愿意找或是找的方法对不对了

很多朋友不是没有资料,大多都是有几十上百个G,但是杂乱无章,不知道怎么看从哪看起,甚至是看后就忘

如果大家觉得自己在网上找的资料非常杂乱、不成体系的话,我也分享一套给大家,比较系统,我平常自己也会经常研读。

2021最新上万页的大厂面试真题

七大模块学习资料:如NDK模块开发、Android框架体系架构…

只有系统,有方向的学习,才能在段时间内迅速提高自己的技术。

这份体系学习笔记,适应人群:
**第一,**学习知识比较碎片化,没有合理的学习路线与进阶方向。
**第二,**开发几年,不知道如何进阶更进一步,比较迷茫。
第三,到了合适的年纪,后续不知道该如何发展,转型管理,还是加强技术研究。如果你有需要,我这里恰好有为什么,不来领取!说不定能改变你现在的状态呢!
由于文章内容比较多,篇幅不允许,部分未展示内容以截图方式展示

《互联网大厂面试真题解析、进阶开发核心学习笔记、全套讲解视频、实战项目源码讲义》点击传送门即可获取!

项目、讲解视频,并且会持续更新!**

如果你觉得这些内容对你有帮助,可以扫码获取!!(备注:Android)

[外链图片转存中…(img-lYIHOP1R-1713713428575)]

学习分享

在当下这个信息共享的时代,很多资源都可以在网络上找到,只取决于你愿不愿意找或是找的方法对不对了

很多朋友不是没有资料,大多都是有几十上百个G,但是杂乱无章,不知道怎么看从哪看起,甚至是看后就忘

如果大家觉得自己在网上找的资料非常杂乱、不成体系的话,我也分享一套给大家,比较系统,我平常自己也会经常研读。

2021最新上万页的大厂面试真题

[外链图片转存中…(img-CbMeEplL-1713713428576)]

七大模块学习资料:如NDK模块开发、Android框架体系架构…

[外链图片转存中…(img-YU1BIl7N-1713713428577)]

只有系统,有方向的学习,才能在段时间内迅速提高自己的技术。

这份体系学习笔记,适应人群:
**第一,**学习知识比较碎片化,没有合理的学习路线与进阶方向。
**第二,**开发几年,不知道如何进阶更进一步,比较迷茫。
第三,到了合适的年纪,后续不知道该如何发展,转型管理,还是加强技术研究。如果你有需要,我这里恰好有为什么,不来领取!说不定能改变你现在的状态呢!
由于文章内容比较多,篇幅不允许,部分未展示内容以截图方式展示

《互联网大厂面试真题解析、进阶开发核心学习笔记、全套讲解视频、实战项目源码讲义》点击传送门即可获取!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值