github上一款特别的侧滑

知识分享:

首先看图,我只是大自然的搬运工,想实现这种特效的请点击连接下载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
  }

}
时间: 2024-12-24 23:29:23

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

GitHub 上 10 款免费开源 Windows 工具

GitHub 上 10 款免费开源 Windows 工具 GitHub 是如今所有开源事物的中央仓库, 这个网站最近发布了一个叫做<2016 Octoverse  状态报告>,详细列出了从去年起其一系列亮点, 包括总的活跃用户数,最常见的 emoji 表情,最常被使用的编程语言,等等. 而最令人感到惊奇的是什么呢? 微软竟然位列总活跃贡献榜首 - 在关注量上击败了 Facebook, Google, Atom, 以及 NPM. 我觉得不可思议的就是微软这么快就可以转变思维拥抱开源.一切都是从 

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

转载:https://www.oschina.net/news/79500/57-most-popular-deep-learning-project-at-github 本文整理了 GitHub 上最流行的 57 款深度学习项目(按 stars 排名).最后更新:2016.08.09 1.TensorFlow 使用数据流图计算可扩展机器学习问题 TensorFlow 是谷歌的第二代机器学习系统,按照谷歌所说,在某些基准测试中,TensorFlow 的表现比第一代的 DistBelief 快了2

github上bootstrap3后台管理平台html框架

转:https://blog.csdn.net/li396864285/article/details/78095814 github上9款最值得收藏的bootstrap3后台管理平台html框架 AdminLTE Gentelella Admin Vali Admin ModularAdmin Metis Ace Light Bootstrap Dashboard Material Dashboard Clearmin 1. AdminLTE AdminLTE是一个完全响应的后台管理模板.基于

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

下拉刷新 EGOTableViewPullRefresh - 最早的下拉刷新控件. SVPullToRefresh - 下拉刷新控件. MJRefresh - 仅需一行代码就可以为UITableView或者CollectionView加上下拉刷新或者上拉刷新功能.可以自定义上下拉刷新的文字说明.具体使用看“使用方法”. (国人写) XHRefreshControl - XHRefreshControl 是一款高扩展性.低耦合度的下拉刷新.上提加载更多的组件.(国人写) CBStoreHouseR

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

作为开源开发领域的基石,"所有漏洞皆属浅表"已经成为一条著名的原则甚至是信条.作为广为人知的Linus定律,当讨论开源模式在安全方面的优势时,开放代码能够提高项目漏洞检测效率的理论也被IT专业人士们所普遍接受. 恶意软件分析.渗透测试.计算机取证--GitHub托管着一系列引人注目的安全工具.足以应对各类规模下计算环境的实际需求. GitHub上的十一款热门开源安全工具 作为开源开发领域的基石,"所有漏洞皆属浅表"已经成为一条著名的原则甚至是信条.作为广为人知的Li

10款GitHub上最火爆的国产开源项目

衡量一个开源产品好不好,看看产品在 GitHub 的 Star 数量就知道了.由此可见,GitHub 已经沦落为开源产品的"大众点评"了.一个开源产品希望快速的被开发者知道.快速的获取反馈,放到 GitHub 上面就可以了.GitHub上有无数大牌产品:Bootstrap.JQeury.bower.Nginx 等等,可惜都是外国人搞出来的,他们都有一个共同的特点:全英文. 感谢 GitHub,让我们有了一个优秀的共享平台,享受思想碰撞.参与优秀项目的激情.下面我跟广大的程序猿们,分享一

GitHub 上最热的10款国产开源软件

衡量一个开源产品好不好,看看产品在 GitHub 的 Star 数量就知道了.由此可见,GitHub 已经沦落为开源产品的“大众点评”了.一个开源产品希望快速的被开发者知道.快速的获取反馈,放到 GitHub 上面就可以了.GitHub上有无数大牌产品:Bootstrap.JQeury.bower.Nginx 等等,可惜都是外国人搞出来的,他们都有一个共同的特点:全英文. 感谢 GitHub,让我们有了一个优秀的共享平台,享受思想碰撞.参与优秀项目的激情.下面我跟广大的程序猿们,分享一下 Git

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

衡量一个开源产品好不好,看看产品在Github的Star数量就知道了.由此可见,Github已经沦落为开源产品的“大众点评”了. 一个开源产品希望快速的被开发者知道.快速的获取反馈,放到Github上面就可以了. Github上有无数大牌产品:Bootstrap.JQeury.bower.Nginx……可惜都是歪果人搞出来的,他们都有一个共同的特点:全英文. 中国人普遍认为,英语和高数是这个世界上最难的学科.即使这个国家每天都向美国欧洲澳洲等国家地区输出大量的中国人,并且一直在中学奥数上保持让人

这是一款可以查阅Github上的热门趋势的APP

随时查阅当前Github上的热门趋势.使用Material Design设计风格,和流行的MVP+Retrofit+RxJava框架.数据抓取自https://github.com/trending Features Material Design设计风格 MVP结构 使用Retrofit网络请求 多种内置皮肤可以切换 可订阅常见编程语言 支持搜索 Demo Thanks 感谢以下开源协议 compile 'com.android.support:appcompat-v7:25.0.1' com