知识分享:

首先看图,我只是大自然的搬运工,想实现这种特效的请点击连接下载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. Cent OS服务器配置(JDK+Tomcat+MySQL)

    本文摘自:Cent OS服务器配置(JDK+Tomcat+MySQL) 学习tar解压 解压 tar 文件 tar -zxvf apache-tomcat-6.0.35.tar.gz tomcat   ...

  2. C++ 中引用与指针的区别

    1.引用只是变量的一个别名,并不占用内存空间,而指针是一个变量,里面保存着被指向的变量在内存中的地址: 2 引用只能在定义时被初始化一次,之后不可变,而指针可变: 3 引用没有 const,指针有 c ...

  3. 介绍一种css水平垂直居中的方法(非常好用!)

    这次介绍一下一个水平垂直居中的css方法,这个方法可以说是百试百灵,废话不多说,直接附上代码: html,body{ width:100%; height:100%; } 你需要居中的元素{ posi ...

  4. MongoDB学习笔记——文档操作之增删改

    插入文档 使用db.COLLECTION_NAME.insert() 或 db.COLLECTION_NAME.save() 方法向集合中插入文档 db.users.insert( { user_id ...

  5. centos7 拨号之后添加路由

    问题:拨号主机再自动拨号(/sbin/ifdown ppp0;/sbin/ifup ppp0)之后,无法上网(没有添加路由) 思路:在拨号程序中添加路由代码 vim /sbin/ifup { slee ...

  6. HDU 4421 Bit Magic (图论-2SAT)

    Bit Magic Problem Description Yesterday, my teacher taught me about bit operators: and (&), or ( ...

  7. 烂泥:KVM、kickstart与NFS集成

    本文由秀依林枫提供友情赞助,首发于烂泥行天下. 其实这篇文章原本是可以不写的,不过为了学习NFS的使用形式还是写下,算是作为一个笔记. 有关NFS的搭建与配置,可以参考我以前的文档<烂泥:NFS ...

  8. (转载)web测试方法总结

    web测试方法总结 一.输入框 1.字符型输入框: (1)字符型输入框:英文全角.英文半角.数字.空或者空格.特殊字符“~!@#¥%……&*?[]{}”特别要注意单引号和&符号.禁止直 ...

  9. uva 10129 play on words——yhx

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABNUAAANeCAYAAAA1BjiHAAAgAElEQVR4nOydabWsuhaFywIasIAHJK

  10. 渐进记号 Asymptotic Notations-------geeksforgeeks 翻译

    我们已经简单的讨论了下渐进分析以及最坏,平均和最佳情况的分析.渐进分析的主要思想是分析算法的效率,不用依靠计算机的具体快慢,不需要实现这个算法,也不需要真正去计算时间.渐进记号是一种数学的工具来表示渐 ...