知识分享:

首先看图,我只是大自然的搬运工,想实现这种特效的请点击连接下载github地址忘掉了,。。。。http://download.csdn.net/detail/lj419855402/8602281

主要实现代码,利用AS编译。

package net.xpece.material.navigationdrawer.sample.ui;

import android.annotation.SuppressLint;
import android.content.res.Configuration;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBarDrawerToggle;
import android.view.Gravity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast; import com.sqisland.android.sliding_pane_layout.CrossFadeSlidingPaneLayout; import net.xpece.material.navigationdrawer.NavigationDrawerUtils;
import net.xpece.material.navigationdrawer.descriptors.BaseNavigationItemDescriptor;
import net.xpece.material.navigationdrawer.descriptors.NavigationItemDescriptor;
import net.xpece.material.navigationdrawer.descriptors.NavigationSectionDescriptor;
import net.xpece.material.navigationdrawer.descriptors.SimpleNavigationItemDescriptor;
import net.xpece.material.navigationdrawer.internal.Utils;
import net.xpece.material.navigationdrawer.list.NavigationListFragmentCallbacks;
import net.xpece.material.navigationdrawer.list.SupportCompactNavigationListFragment;
import net.xpece.material.navigationdrawer.list.SupportNavigationListFragment;
import net.xpece.material.navigationdrawer.sample.widget.ToggleNavigationItemDescriptor;
import net.xpece.materialnavigationdrawersample.BuildConfig;
import net.xpece.materialnavigationdrawersample.R; import java.util.ArrayList;
import java.util.List; import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.Optional;
import timber.log.Timber; public class MainActivity extends ActionBarActivity implements NavigationListFragmentCallbacks { // @InjectView(R.id.app_bar)
// Toolbar mToolbar; private static final List<NavigationSectionDescriptor> SECTIONS = new ArrayList<>();
private static final NavigationSectionDescriptor PRIMARY_SECTION;
private static final NavigationSectionDescriptor PINNED_SECTION; static {
PRIMARY_SECTION = new NavigationSectionDescriptor()
.addItem(new SimpleNavigationItemDescriptor(1).text("Goodbye").badge("Hello").sticky()
.iconResource(R.drawable.ic_star_black_24dp)
.activeColorResource(R.color.material_red_500)
.badgeColorResource(R.color.material_red_500))
.addItem(new SimpleNavigationItemDescriptor(2).text("Yes").badge("No").sticky()
.iconResource(R.drawable.ic_star_black_24dp)
.passiveColorResource(R.color.material_amber_500).iconColorAlwaysPassiveOn()
.badgeColorResource(R.color.material_amber_500))
.addItem(new SimpleNavigationItemDescriptor(3).text("Stop").badge("Go, go, go").sticky()
// .iconResource(R.drawable.ic_star_black_24dp)
.iconResource(android.R.color.transparent)
.activeColorResource(R.color.material_light_green_500)
.badgeColorResource(R.color.material_light_green_500))
.addItem(new SimpleNavigationItemDescriptor(4).text("Why").badge("I don't know").sticky()
.iconResource(0)
.activeColorResource(R.color.material_light_blue_500).iconColorAlwaysPassiveOn()
.badgeColor(0));
SECTIONS.add(PRIMARY_SECTION);
NavigationSectionDescriptor section2 = new NavigationSectionDescriptor().heading("Want more?")
.addItem(new ToggleNavigationItemDescriptor(8).checked(true));
SECTIONS.add(section2);
NavigationSectionDescriptor section3 = new NavigationSectionDescriptor()
.addItem(new BaseNavigationItemDescriptor(6).text("Settings")
.iconResource(R.drawable.ic_settings_black_24dp))
.addItem(new BaseNavigationItemDescriptor(7).text("Help & feedback")
.iconResource(R.drawable.ic_help_black_24dp));
PINNED_SECTION = section3; if (BuildConfig.DEBUG) Timber.plant(new Timber.DebugTree());
} @Optional
@InjectView(R.id.drawer_layout)
DrawerLayout mDrawerLayout; @Optional
@InjectView(R.id.sliding_layout)
CrossFadeSlidingPaneLayout mSlidingLayout; @Optional
@InjectView(R.id.navigation_container)
ViewGroup mNavigationContainer; @InjectView(R.id.content)
View mContent; ActionBarDrawerToggle mDrawerToggle; SupportNavigationListFragment mNavFragment;
SupportCompactNavigationListFragment mNavFragmentCompact; // retain this
Long mSelectedItem; // so I can show new toast immediately
Toast mToast = null; @SuppressLint("RtlHardcoded")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.inject(this); // only setup drawer layout if there is a drawer in current layout (on phones)
if (mDrawerLayout != null) {
// setup drawer toggle, because i use native Action Bar and nav drawer below it
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, android.R.string.untitled, android.R.string.untitled);
mDrawerLayout.setDrawerListener(mDrawerToggle); NavigationDrawerUtils.fixMinDrawerMargin(mDrawerLayout); // apply navigation margin fix // the following are correct the RIGHT drawer drops shadow to LEFT and vice versa
mDrawerLayout.setDrawerShadow(R.drawable.mnd_shadow_left, Gravity.RIGHT);
mDrawerLayout.setDrawerShadow(R.drawable.mnd_shadow_right, Gravity.LEFT);
} // only setup sliding layout if there is one in current layout (on tablets)
if (mSlidingLayout != null) {
mSlidingLayout.setSliderFadeColor(0);
mSlidingLayout.setShadowResourceLeft(R.drawable.mnd_shadow_left);
mSlidingLayout.setShadowResourceRight(R.drawable.mnd_shadow_right);
NavigationDrawerUtils.setProperNavigationDrawerWidth(mNavigationContainer); Drawable d = getResources().getDrawable(R.drawable.ic_menu_white_24dp);
int c = Utils.getColor(getSupportActionBar().getThemedContext(), R.attr.colorControlNormal, 0);
d = Utils.tintDrawable(d, c);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeAsUpIndicator(d);
} // on phones there is no compact version, so null check is in place
mNavFragmentCompact = (SupportCompactNavigationListFragment) getSupportFragmentManager().findFragmentById(R.id.navigation_drawer_compact);
if (mNavFragmentCompact != null) {
List<NavigationSectionDescriptor> sections = new ArrayList<>();
sections.add(PRIMARY_SECTION);
sections.add(PINNED_SECTION);
mNavFragmentCompact.setHeaderView(View.inflate(this, R.layout.mnd_custom_header_compact, null), false);
mNavFragmentCompact.setSections(sections);
} // since the fragment is defined in layout, i can call this safely in onCreate
mNavFragment = (SupportNavigationListFragment) getSupportFragmentManager().findFragmentById(R.id.navigation_drawer);
if (mNavFragment != null) {
NavigationDrawerUtils.setProperNavigationDrawerWidth(mNavFragment.getView());
// set up the nav fragment
mNavFragment.setHeaderView(View.inflate(this, R.layout.mnd_custom_header, null), true);
mNavFragment.setSections(SECTIONS);
mNavFragment.setPinnedSection(PINNED_SECTION); mNavFragment.setBackgroundResource(R.drawable.a7x_aligned);
} if (savedInstanceState == null) {
mSelectedItem = 1l;
} else {
mSelectedItem = savedInstanceState.getLong("mSelectedItem");
}
} @Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState); if (mDrawerToggle != null) mDrawerToggle.syncState(); if (savedInstanceState == null) {
if (mNavFragment != null) mNavFragment.setSelectedItem(mSelectedItem);
if (mNavFragmentCompact != null) mNavFragmentCompact.setSelectedItem(mSelectedItem);
}
} @Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig); if (mDrawerToggle != null) mDrawerToggle.onConfigurationChanged(newConfig);
} @Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putLong("mSelectedItem", mSelectedItem);
} @Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
} @Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
// AUTOMATICALLY ONLY ON 4.1+ !!! int id = item.getItemId(); //noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
} else if (id == android.R.id.home) {
if (mDrawerToggle != null) return mDrawerToggle.onOptionsItemSelected(item);
if (mSlidingLayout != null) {
if (mSlidingLayout.isOpen()) mSlidingLayout.closePane();
else mSlidingLayout.openPane();
return true;
}
} return super.onOptionsItemSelected(item);
} @Override
public void onNavigationItemSelected(View view, int position, long id, NavigationItemDescriptor item) {
if (mToast != null) mToast.cancel();
mToast = Toast.makeText(this, "Item #" + id + " on position " + position + " selected!", Toast.LENGTH_SHORT);
mToast.show(); if (item != null && item.isSticky()) {
// if it is sticky, save selected position and mark in all fragments
mSelectedItem = id;
if (mNavFragment != null) mNavFragment.setSelectedItem(id);
if (mNavFragmentCompact != null) mNavFragmentCompact.setSelectedItem(id);
} else {
// if (mNavFragment != null) mNavFragment.setSelectedItem(id);
// if (mNavFragmentCompact != null) mNavFragmentCompact.setSelectedItem(id);
} if (id == 8) return; // custom toggle does not close the drawer // if (mDrawerLayout != null) mDrawerLayout.closeDrawers(); // uncomment to close drawer on item selected
} }

github上一款特别的侧滑的更多相关文章

  1. GitHub 上 57 款最流行的开源深度学习项目

    转载:https://www.oschina.net/news/79500/57-most-popular-deep-learning-project-at-github GitHub 上 57 款最 ...

  2. GitHub 上 57 款最流行的开源深度学习项目【转】

    GitHub 上 57 款最流行的开源深度学习项目[转] 2017-02-19 20:09 334人阅读 评论(0) 收藏 举报 分类: deeplearning(28) from: https:// ...

  3. GitHub 上 10 款免费开源 Windows 工具

    GitHub 上 10 款免费开源 Windows 工具 GitHub 是如今所有开源事物的中央仓库, 这个网站最近发布了一个叫做<2016 Octoverse  状态报告>,详细列出了从 ...

  4. Github上关于iOS的各种开源项目集合(强烈建议大家收藏,查看,总有一款你需要)

    下拉刷新 EGOTableViewPullRefresh - 最早的下拉刷新控件. SVPullToRefresh - 下拉刷新控件. MJRefresh - 仅需一行代码就可以为UITableVie ...

  5. 28款GitHub最流行的开源机器学习项目,推荐GitHub上10 个开源深度学习框架

    20 个顶尖的 Python 机器学习开源项目 机器学习 2015-06-08 22:44:30 发布 您的评价: 0.0 收藏 1收藏 我们在Github上的贡献者和提交者之中检查了用Python语 ...

  6. 【转】10款GitHub上最火爆的国产开源项目

    将开源做到极致,提高效率方便更多用户 接触开源时间虽然比较短但是后续会努力为开源社区贡献自己微薄的力量 衡量一个开源产品好不好,看看产品在 GitHub 的 Star 数量就知道了.由此可见,GitH ...

  7. Github上关于iOS的各种开源项目集合2(强烈建议大家收藏,查看,总有一款你需要)

    资源list:Github上关于大数据的开源项目.论文等合集 Awesome Big Data A curated list of awesome big data frameworks, resou ...

  8. 点评10款Github上最火爆的国产开源项目

    衡量一个开源产品好不好,看看产品在Github的Star数量就知道了.由此可见,Github已经沦落为开源产品的“大众点评”了. 一个开源产品希望快速的被开发者知道.快速的获取反馈,放到Github上 ...

  9. GitHub 上的十一款热门开源安全工具

    作为开源开发领域的基石,“所有漏洞皆属浅表”已经成为一条著名的原则甚至是信条.作为广为人知的Linus定律,当讨论开源模式在安全方面的优势时,开放代码能够提高项目漏洞检测效率的理论也被IT专业人士们所 ...

随机推荐

  1. iOSQuartz2D-01-核心要点

    简介 作用 绘制 绘制图形 : 线条\三角形\矩形\圆\弧等 绘制文字 绘制\生成图片(图像) 读取\生成PDF 截图\裁剪图片 自定义UI控件(通常为内部结构较复杂的控件) UIKit中的绝大部分控 ...

  2. IOS之未解问题--给UITableView提取UITableViewDataSource并封装瘦身失败

    前言:阅读了<更轻量的 View Controllers>,发现笔者这个优化重构代码的想法真的很不错,可以使得抽取的UITableViewDataSource独立写在一个类文件里,并且也写 ...

  3. apt-get

    更新版本: apt-get --reinstall install apache2 卸载: apt-get remove apache2          只删除软件包 apt-get autorem ...

  4. 百度推出的echarts,制表折线图柱状图饼图等的超级工具(转)

    一.简介: 1.绘制数据图表,有了它,想要网页上绘制个折线图.柱状图,从此easy. 2.使用这个百度的echarts.js插件,是通过把图片绘制在canvas上在显示在页面上. 官网对echarts ...

  5. PL/SQL之--游标

    一.游标简介 在PL/SQL中执行SELECT.INSERT.DELETE和UPDATE语句时,ORACLE会在内存中为其分配上下文区(Context Area),也称为缓冲区.游标是指向该区的一个指 ...

  6. ubuntu创建、删除文件及文件夹方法

    mkdir 目录名         => 创建一个目录 rmdir 空目录名      => 删除一个空目录 rm 文件名 文件名   => 删除一个文件或多个文件 rm –rf 非 ...

  7. JQ插件

    什么是插件 插件(plugin)是JQuery的扩展(Extension),以JQuery的核心代码为基础,是一种遵循一定规范的应用程序接口编写出来的程序. 插件的引入 引入jquery.js文件 引 ...

  8. 第三篇 :微信公众平台开发实战Java版之请求消息,响应消息以及事件消息类的封装

    微信服务器和第三方服务器之间究竟是通过什么方式进行对话的? 下面,我们先看下图: 其实我们可以简单的理解: (1)首先,用户向微信服务器发送消息: (2)微信服务器接收到用户的消息处理之后,通过开发者 ...

  9. FAQ-Ubuntu12.04 15.04禁止移动介质自动播放

    网上有有很多关于Ubuntu10.04关闭移动介质自动播放的方法,包括在文件管理器里面设置或者使用gconf-editor,但是从12.04开始这两种方法都不再好用了,关于移动介质的处理方法被移到了S ...

  10. tomcat 部署脚本

    将一下3个脚本放到一个目录里,做成一个 python 的包即可使用 脚本介绍 操作服务脚本 #!/usr/bin/env python # _*_coding:utf-8_*_ # Author: & ...