开源库guillotine使用解析
来源:互联网 发布:pmf文件怎么提取出数据 编辑:程序博客网 时间:2024/06/15 08:15
转载请注明出处:王亟亟的大牛之路
最近在忙跳槽的事,导致好多天没敲代码,昨天正好看到这个库终于搞通然后就写篇文章吧(之前Gradle怎么都有问题,真是坑)
看多了千篇一律的左右抽屉形式的主Menu和Content部分,看这个菜单还是一种新感觉吧,话不多说先上效果图。
大致就是按左上角的红色/蓝色按钮然后显示菜单和主内容。
Git上的项目,多数是Gradle建包的所以就配合吧,包很简单,一个Lib包一个Sample的项目包。(拿来一族表示,能用就行,好,来看看怎么用)
要使用这个库要写一个Application类并且在manifest里注册这个类
ps:用过SlidingMenu的小伙伴一定知道,他们都要一个类似的这个类
public class App extends Application { private static final String CANARO_EXTRA_BOLD_PATH = "fonts/canaro_extra_bold.otf"; public static Typeface canaroExtraBold; @Override public void onCreate() { super.onCreate(); initTypeface(); } private void initTypeface() { canaroExtraBold = Typeface.createFromAsset(getAssets(), CANARO_EXTRA_BOLD_PATH); }}
大牛还写了一个自定义的TextView其实,这个类有没有无所谓了,我们使用的时候可以无视他
public class CanaroTextView extends TextView { public CanaroTextView(Context context) { this(context, null); } public CanaroTextView(Context context, AttributeSet attrs) { this(context, attrs, 0); } public CanaroTextView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); setTypeface(App.canaroExtraBold); }}
主Activity
这里大牛用了一个注解来解决他的FindViewById的事,类库地址http://jakewharton.github.io/butterknife/,这里不做解释,不过看了看还是蛮简单的,可以以后在项目中试用下
public class MainActivity extends AppCompatActivity { private static final long RIPPLE_DURATION = 250; @InjectView(R.id.toolbar) Toolbar toolbar; @InjectView(R.id.root) FrameLayout root; @InjectView(R.id.content_hamburger) View contentHamburger; Button testbuttonbutton; @InjectView(R.id.contentbutton) Button contentbutton; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity); ButterKnife.inject(this); if (toolbar != null) { setSupportActionBar(toolbar); getSupportActionBar().setTitle(null); } View guillotineMenu = LayoutInflater.from(this).inflate(R.layout.guillotine, null); root.addView(guillotineMenu); new GuillotineAnimation.GuillotineBuilder(guillotineMenu, guillotineMenu.findViewById(R.id.guillotine_hamburger), contentHamburger) .setStartDelay(RIPPLE_DURATION) .setActionBarViewForAnimation(toolbar) .build(); testbuttonbutton =(Button)guillotineMenu.findViewById(R.id.testbutton); listener(); } private void listener(){ testbuttonbutton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Toast.makeText(MainActivity.this,"menuButton",Toast.LENGTH_SHORT).show(); } }); contentbutton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Toast.makeText(MainActivity.this,"contentbutton",Toast.LENGTH_SHORT).show(); } }); }}
逻辑:在主页面吐司一个“contentbutton”,然后在菜单页面吐司一个“menuButton”。
我们根本不需要对展示层做什么修改,照搬用就行了,很方便。
manifest文件
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.yalantis.guillotine.sample"> <application android:name=".App" android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme"> <activity android:name=".activity.MainActivity" android:screenOrientation="portrait"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application></manifest>
源码地址:http://yunpan.cn/ccNJpEzA4NZGd 访问密码 7a65
谢谢大家
2 0
- 开源库guillotine使用解析
- IE/Win Guillotine Bug
- 开源库Fab-Transformation简单使用解析
- xml解析(使用pull解析)
- 使用JSR172解析XML
- 使用Jdom解析XML
- 使用 dom4j 解析 XML
- 使用SAX解析XML
- 使用 dom4j 解析 XML
- 使用Libxml2解析xml
- 使用 dom4j 解析 XML
- 使用 dom4j 解析 XML
- 使用JDOM解析XML
- 使用JDOM解析XML
- 使用 dom4j 解析 XML
- 使用SAX解析XML
- 使用jdom解析xml
- 使用xmlbeans解析xml
- iOS 检测设备旋转状态
- Hdu 1051
- ibatis之——学生信息管理实例
- 机器学习算法
- centos 常用实用命令
- 开源库guillotine使用解析
- 小应用大智慧-Coredump故障分析
- android Application类的详细介绍
- C语言标识符
- Qt之界面美化输入框
- jQuery EasyUI的DataGrid 数据行上右键菜单,并Check行
- Hadoop入门进阶课程13--Chukwa介绍与安装部署
- 勘探油田-Acm系统第3267题
- web基础小总结